第一步:创建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;
/

解决方案 »

  1.   

    在触发器里面使用sequence.nextval作为id的值
      

  2.   

    http://expert.csdn.net/Expert/topic/1188/1188814.xml?temp=.1202661
      

  3.   

    创建sequence
    执行insert 的时候使用.nextval就ok了比如
    create sequence a start with 1 maxvalue 999999 nocycle;
    假设表为test,只有一个字段id,number型的
    insert into test values(a.nextval);
      

  4.   

    对,用序列好发生器是最简单的,如下所示:
    CREATE OR REPLACE SEQUENCE emp_sequence
        INCREMENT BY 1
        START WITH 1
        NOMAXVALUE 20000000000
        NOCYCLE
        CACHE 10;