ORACLE如何实现ID自动增长

create  sequence TBL_PIC_PRODUCT_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 1
increment by 1
cache 20;

create or replace trigger TBL_PIC_PRODUCT_TRIG before insert on TBL_PIC_PRODUCT
referencing old as old new as new
for each row
declare next_id number;
begin
    select
        TBL_PIC_PRODUCT_SEQ.nextval
    into
        next_id
    from
        dual;

    :new.info_id:=next_id;
end;
/


---------------
--建立序列  
  create   sequence   seq_name  
  increment   by   1  
  start   with   1  
  maxvalue   99999999  
  nocycle  
  cache   10  
   
  --调用:  
  insert   into   table(id,name)   values(seq_name.nextval,yourname);

-----------
第一步:创建SEQUENCE  
  create   sequence   s_country_id   increment   by   1   start   with   1   maxvalue   999999999;  
  第二步:创建一个基于该表的before   insert   触发器,在触发器中使用该SEQUENCE  
  create   or   replace   trigger   bef_ins_t_country_define  
  before   insert   on   t_country_define  
  referencing   old   as   old   new   as   new   for   each   row  
  begin  
  select   s_country_id.nextval   into   :new.country_id   from   dual;  
  end;  
  / 

你可能感兴趣的:(oracle,cache)