第一步:创建sequence 
create sequence seq_id increment by 1 start with 1 maxvalue 999999999; 第二步:创建一个基于该表的before insert 触发器tri_id,在触发器中使用该sequence假设table_in为插入的表名,其中id 为此表的一个要自动增加的字段 create or replace trigger tri_id 
before insert on table_in 
referencing old as old new as new 
for each row declare 
   i number; begin 
   
   select seq_id.nextval into i from dual; 
   :new.id :=i; 
end;

解决方案 »

  1.   

    简化楼上:
    create or replace trigger tri_id 
    before insert on table_in 
    for each row 
    begin  
       select seq_id.nextval into :new.id from dual; 
    end;
      

  2.   

    如上面,先创建一个序列sequence
      

  3.   

    --建序列
    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');
      

  4.   

    alter talbe tablename add  id  int inentidy(1,1) 0