>>梦想乡<<

Oracle通过JDBC插入数据时,自增ID如何自动增长

一、通过触发器的方式

CREATE OR REPLACE TRIGGER tg_test
BEFORE INSERT ON Userinfo
FOR EACH ROW WHEN (new.userNo is null)
begin
select SEQ_Userinf.nextval into:new.userNO from dual;
end;

 插入语句为:

insert into CATEGORY_EXPERT_GRADE (CATEGORY_FK, EXPERT_FK,GRADE,SAVE_DATE, FLAG, EXTEND1, EXTEND2, EXTEND3) values ( ?, ?,?, ?, ?, ?, ?, ?) 

二、通过函数的方式

    create or replace function get_seq return number is  
      Result number;  
    begin  
      select Sequence_Shzj.nextval into Result from dual;  
      return(Result);  
    end get_seq;  

 插入语句为:

insert into CATEGORY_EXPERT_GRADE (PK, CATEGORY_FK, EXPERT_FK,GRADE,SAVE_DATE, FLAG, EXTEND1, EXTEND2, EXTEND3) values (get_seq, ?, ?,?, ?, ?, ?, ?, ?) 

 

posted @ 2018-04-09 10:30  文苏  阅读(3892)  评论(0编辑  收藏  举报