兰州网站建设 冰雨,wordpress怎么搭建成论坛,关于备案空壳网站清理通知,100%能上热门的文案创作不易 只因热爱!! 热衷分享#xff0c;一起成长! “你的鼓励就是我努力付出的动力” 1.数据库oracle自增主键字段思维导图
在Oracle数据库中#xff0c;可以通过创建序列#xff08;SEQUENCE#xff09;来实现自增功能。但也可以不在数据库中实现#xff0c;而是通过程…创作不易 只因热爱!! 热衷分享一起成长! “你的鼓励就是我努力付出的动力” 1.数据库oracle自增主键字段思维导图
在Oracle数据库中可以通过创建序列SEQUENCE来实现自增功能。但也可以不在数据库中实现而是通过程序中实现以下是XX大厂的应用端对oracle表主键字段的类似自增并可一次多增的方法分析后附代码。 刚使用时觉得挺有学习意义分享一下通过程序实现表主键的自增适合任意数据库。 国产数据库也是可以用此方法通过程序实现。 #mermaid-svg-CrS4KH2WBvXfJ6gL {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-CrS4KH2WBvXfJ6gL .error-icon{fill:#552222;}#mermaid-svg-CrS4KH2WBvXfJ6gL .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-CrS4KH2WBvXfJ6gL .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-CrS4KH2WBvXfJ6gL .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-CrS4KH2WBvXfJ6gL .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-CrS4KH2WBvXfJ6gL .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-CrS4KH2WBvXfJ6gL .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-CrS4KH2WBvXfJ6gL .marker{fill:#333333;stroke:#333333;}#mermaid-svg-CrS4KH2WBvXfJ6gL .marker.cross{stroke:#333333;}#mermaid-svg-CrS4KH2WBvXfJ6gL svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-CrS4KH2WBvXfJ6gL .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-CrS4KH2WBvXfJ6gL .cluster-label text{fill:#333;}#mermaid-svg-CrS4KH2WBvXfJ6gL .cluster-label span{color:#333;}#mermaid-svg-CrS4KH2WBvXfJ6gL .label text,#mermaid-svg-CrS4KH2WBvXfJ6gL span{fill:#333;color:#333;}#mermaid-svg-CrS4KH2WBvXfJ6gL .node rect,#mermaid-svg-CrS4KH2WBvXfJ6gL .node circle,#mermaid-svg-CrS4KH2WBvXfJ6gL .node ellipse,#mermaid-svg-CrS4KH2WBvXfJ6gL .node polygon,#mermaid-svg-CrS4KH2WBvXfJ6gL .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-CrS4KH2WBvXfJ6gL .node .label{text-align:center;}#mermaid-svg-CrS4KH2WBvXfJ6gL .node.clickable{cursor:pointer;}#mermaid-svg-CrS4KH2WBvXfJ6gL .arrowheadPath{fill:#333333;}#mermaid-svg-CrS4KH2WBvXfJ6gL .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-CrS4KH2WBvXfJ6gL .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-CrS4KH2WBvXfJ6gL .edgeLabel{background-color:#e8e8e8;text-align:center;}#mermaid-svg-CrS4KH2WBvXfJ6gL .edgeLabel rect{opacity:0.5;background-color:#e8e8e8;fill:#e8e8e8;}#mermaid-svg-CrS4KH2WBvXfJ6gL .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-CrS4KH2WBvXfJ6gL .cluster text{fill:#333;}#mermaid-svg-CrS4KH2WBvXfJ6gL .cluster span{color:#333;}#mermaid-svg-CrS4KH2WBvXfJ6gL div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-CrS4KH2WBvXfJ6gL :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} OK 成功 失败 失败 不存在结果 存在 成功 存在 不存在 三次失败后 失败1失败2失败3 失败 成功 参数判断 更新表table 更新成功, 再看结果记录 判断是否 存在记录 插入新记录 回滚,返回-1 提交, 获取新记录返回 继续更新表 最多三次 插入新记录 回滚,返回, 重新更新表 2.oracle表主键字段自增使用说明
表SYS_XTCS主键自增1 每次程序调用当前主键值autovaluefunc_getmax(sqlhis,‘SYS_XTCS’,1) 获取主键后写入表 insert into SYS_XTCS values(autovalue,…) 表SYS_XTCS主键增加多行如9每次程序调用当前主键值autovaluefunc_getmax(sqlhis,‘SYS_XTCS’,9) 获取主键后写入表 insert all …或游标循环写入… 如下首列表名称BMC当前主键值DQZ数据库连接名 transaction
3.通过程序实现ora表主键自增代码示例
代码是powerbuilder写的
// func_getmax()
// 功能:取最大值, 错误时返回:-1
// 传参N, 类型 , 参数名
// 传参1, transaction , aoTransaction
// 传参2, string , asTableName
// 传参3, integer , aiNeedCountDecimal{0} llValue
Long llCount, llRetryIf IsNull(aiNeedCount) Or aiNeedCount 1 ThenReturn -1
End IfProcess_Begin:
func_begin_transaction(aoTransaction)
UPDATE SYS_MAX SET DQZ DQZ :aiNeedCount WHERE BMC :asTableName USING aoTransaction;If aoTransaction.SQLCode 0 Then // update失败判断是否存在记录SELECT COUNT(*) INTO :llCount FROM SYS_MAX WHERE BMC :asTableName USING aoTransaction;If llCount 0 Then // 记录存在继续update(最多三次)llRetry If llRetry 3 ThenGoto Process_ErrorElsefunc_rollback_transaction(aoTransaction)Goto Process_BeginEnd If Else // 记录不存在则插入新记录INSERT INTO SYS_MAX(BMC, DQZ) VALUES (:asTableName, :aiNeedCount) USING aoTransaction;If aoTransaction.SQLCode 0 Then Goto Process_ErrorEnd IfllValue aiNeedCountGoto Process_SuccessEnd If
ElseSELECT COUNT(*) INTO :llCount FROM SYS_MAX WHERE BMC :asTableName USING aoTransaction;If IsNull(llCount) Or llCount 0 Then // 记录不存在则插入新记录INSERT INTO SYS_MAX(BMC, DQZ) VALUES (:asTableName,:aiNeedCount) USING aoTransaction;If aoTransaction.SQLCode 0 Then Goto Process_ErrorEnd IfllValue aiNeedCountGoto Process_SuccessEnd If
End IfSetNull(llValue)
SELECT DQZ INTO :llValue FROM SYS_MAX WHERE BMC :asTableName USING aoTransaction;If IsNull(llValue) Or llValue aiNeedCount ThenGoto Process_Error
End IfProcess_Success:
func_commit_transaction(aoTransaction)Return llValue - aiNeedCount 1Process_Error:
func_rollback_transaction(aoTransaction)Return -1
但行好事莫问前程!
end
**你好呀我是一个医信行业工程师喜欢学习喜欢搞机喜欢各种捣也会持续分享如果喜欢我那就关注我吧**
往期精彩:
作者医信工程师随笔Carltiger_github
图片网络侵删
关注我我们共同成长
“你的鼓励就是我分享的动力”