当前位置:数据库 > Oracle >>

Oracle非主键自增长

Oracle非主键自增长
 
create sequence JCDA_GFYYXX_ID
minvalue 1
maxvalue 99999999
start with 21
increment by 1
cache 20;
 
create or replace trigger  JCDA_GFYYXX_TB_ID_CFQ
 
  before insert on JCDA_GFYYXX_TB         --JCDA_GFYYXX_TB为表名  
  for each row
declare
  -- local variables here
  nextid number;                   --自定义变量,用于存储从序列中取得的值
begin
  IF :new.OBJECTID IS NULL or :new.OBJECTID=0 THEN
      select JCDA_GFYYXX_ID.NEXTVAL     --从序列中取得下一个值,赋给变量nextid
      into nextid
      from DUAL;
      :new.OBJECTID:=nextid;
  end if;
end TRG_MAGGIE_TEST_TID;
 
 
 
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,