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

    在Orcle数据库中,目前自动生成序号的最好的办法就是先建立一个序列,直接取序列的nextval就可以达到你想要的结果。
    create sequence s_country_id increment by 1 start with 1 maxvalue 999999999;
    insert into table_name
    values (s_country_id.nextval,姓名,年龄);
    ok!
      

  2.   

    create or replace sequence test increment by 1 start with 1 maxvalues 99999999999999999;