请问在oracle 8i 下如何对一个表中的记录自动按插入顺序编号(ID)?就是类似 Sql server 中字段的Identity 属性一样。

解决方案 »

  1.   

    Oracle中是适用序列来实现这个功能的.
    一个简单的例子: 
    create table test (no number(4),name char(20));create sequence test_no 
    increment by 1
    start with 1
    maxvalue 100
    nocache
    nocycle;insert into test values(test_no.nextval,'Joan');insert into test values(test_no.nextval,'Peter');commit;
      

  2.   

     sequence
    但是这个不会自动帮你插入,插入的时候要象1楼那样test_no.nextval
      

  3.   

    我一般都这么用:SQL> create table test (no number(4),name char(20));
    表已创建。create sequence test_seq increment by 1 start with 1 maxvalue 100000 nocache nocycle; 
    create or replace trigger trigger_test 
    before  insert on test 
    for each row 
    begin 
    select test_seq.nextval into :new.no from dual; 
    end trigger_test;
    /       SQL> insert into test values(null, 'hello');已创建 1 行。SQL> insert into test(name) values('iihero');已创建 1 行。
      

  4.   

    oracle 的 sequence 对应于 sql server 中 identity