在数据库中执行:
第一步:创建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.   

    用序列:SEQUENCT 可以实现自动增加,
    你要先建一个SEQUENCT ,如CREATE SEQUENCT 序列名 START WITH 起始值 NOCACHE[CACHE int];
    建好后,你就可以在表操作中使用它,如:
    insert into table_a (column_1) values (序列名(nextval));
    每调用一次,序列就自动增加一,或按CACHE 的int 值变化.
      

  2.   

    先创建序列发生器,
    在insert into 时 调用序列发生器
      

  3.   

    在oracle上创建一个序列:
    create sequence s_country_id increment by 1 start with 1 maxvalue 999999999;
    然后再程序里,当向表插入数据时,要自动加一的字段的值用s_country_id.nextval代替就可以了。
    insert into tablename (id,col1,col2) values (s_country_id.nextval,'sdfsdf','asdf');
    其中id是要自动加一的字段。