oracle中没有自动编号
但可以建个序列,然后在INSTER时用 “序列名。NEXTVAL”
可以与自动编号同样的效果。

解决方案 »

  1.   

    TO:w5552
    能具体点吗
    怎样建个序列呀?
      

  2.   

    //序列
    CREATE SEQUENCE TEST_SEQ
      START WITH 1
      NOMAXVALUE
      MINVALUE 0
      NOCYCLE
      CACHE 20
      NOORDER;
    //触发器
    CREATE OR REPLACE TRIGGER SP_TABLENAME  --向表插入ID
    BEFORE INSERT ON 表名
    FOR EACH ROW
    declare
    new_id number;
    begin
    select TEST_SEQ.nextval into 列名 from dual;
    :new.列名 := new_id;
    end;
      

  3.   

    --建一序列:
    create sequence seq_name 
    increment by 1
    start with 1
    maxvalue 99999999999
    nocycle
    cache 10--调用:
        insert into table(id,name) values(seq_name.nextval, 'name')
      

  4.   

    create table a(b int, c  varchar2(5));
    建一个序列
    create sequence a_seq increment by 1 start with 100;
    建一个触发器
    create or replace trigger t_a
    before insert on a
    for each row
    begin
         select s_a.nextval into :new.b from dual;
    end;