表A中有一字段ID,每次向A表中插入一条数据,该ID就自动增加,并且是系统自动给该ID字段插入值,不需在SQL语句中明确指定值,该怎么做?

解决方案 »

  1.   

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

  2.   

    请问一下  select  s_country_id.nextval  into  :new.country_id  from  dual; 中的new.country_id是什么意思?
      

  3.   

    country_id是表中字增的字段,
    select  s_country_id.nextval  into  :new.country_id  from  dual;
    这个sql就是从序列中取出字增数据放到那个字段下