自动增加字段?
第一步:创建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.   

    不建议在触发器中用,一般情况直接在insert中用序列.nextval效率高点
      

  2.   

    to: bzszp(SongZip) and asdf008(棒棒糖) 
    我的意思是这样的:
       比如用户的id,我想每增加一条纪录,id值就自动的加一。不知道在oracle里怎么实现这样的sql语句。
      

  3.   

    一个表:
    info_table:id number
    name varchar2比如你想让id字段自增,需要先创建SEQUENCE,比如名称叫做:SEQ_INFO
    然后 insert into info_table(id,name) values (SEQ_INFO.nextval,'newname')
    即可。