搜索以前的贴子就有了。oracle中怎样将字段建成象SQL2000中的ID自动+1的字段
 两种方法
方法一:
  用触发器建一个序列
   create sequence a_seq increment by 1 start with 100;
建一个触发器, 自动+1
create or replace trigger your_seq_tri
before insert on your_table1 for each row
declare
  next_id number;
begin
  select your_seq.nextval into next_id from dual;
  :new.id := next_id;
end;
方法二:
  建一个序列
     create sequence a_seq increment by 1 start with 100;
   在语句中+1
  insert into tbl(id,....)
     values (a_seq.nextval,....)

解决方案 »

  1.   

    txlicenhe(马可) ( 
    方法二好。
      

  2.   

    用触发器更符合以前用SQL Server的习惯。好像就是一个自增长列:-)
      

  3.   

    oracle中用序列. create sequence seq_name 
    increment by 1
    start with 1
    maxvalue 99999999999
    nocycle
    cache 10--调用:
    insert into table(id,name) values(seq_name.nextval,'yourname');要关联,可以使用行级触发器中的:new来实现将关联字段插入另一表中.
      

  4.   

    ORALCE没有象SQL SERVER的自动增长的列,只能通过序列或别的方法来实现各有各的特点与好处