序列加触发器实现主键自增

2 篇文章 0 订阅
1 篇文章 0 订阅

序列

– Create sequence
create sequence SEQ_MKDD_ZPWSBFJHTY_ID
minvalue 1
maxvalue 999999999
start with 1
increment by 1
cache 20;

触发器

CREATE OR REPLACE TRIGGER “MKDD_ZPWSBFJHTY_TIGGER” BEFORE INSERT ON “MKDD_ZPWSBFJHTY” REFERENCING OLD AS “OLD” NEW AS “NEW” FOR EACH ROW DECLARE
NEXTID NUMBER;
BEGIN
IF :NEW.ID IS NULL OR :NEW.ID=0 THEN
SELECT SEQ_MKDD_ZPWSBFJHTY_ID.NEXTVAL INTO NEXTID FROM DUAL;
:NEW.ID:=NEXTID;
END IF;

END;

xml

INSERT INTO mkdd_zpwsbfjhty select SEQ_MKDD_ZPWSBFJHTY_ID.nextval as id from dual id, unit, tyear, tdate, triptime, tripline, protections, reclosing, disposition, operaunit
         <if test ='null != id'>
             #{id},
         </if>
         <if test ='null != unit'>
             #{unit},
         </if>
         <if test ='null != tyear'>
             #{tyear},
         </if>
         <if test ='null != tdate'>
             #{tdate},
         </if>
         <if test ='null != triptime'>
             #{triptime},
         </if>
         <if test ='null != tripline'>
             #{tripline},
         </if>
         <if test ='null != protections'>
             #{protections},
         </if>
         <if test ='null != reclosing'>
             #{reclosing},
         </if>
         <if test ='null != disposition'>
             #{disposition},
         </if>
         <if test ='null != operaunit'>
             #{operaunit}
         </if>
     </trim>
 </insert>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值