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

  • Post author:
  • Post category:其他


一、通过触发器的方式

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;  

插入语句为: