在MySQL中有:create table eddy1(id int auto_increment primay key);这样的语句
而在Oracle中只能:
   create sequence seq;
  create table eddy2(id number primary key);
  insert into eddy2(seq.nextval);
请问在Oracle中可以不建立sequence,而类似MySQL在create table语句中用auto_increment类似的语句建表吗???望请各位高人指点!!

解决方案 »

  1.   


    --Oracle自动增长字段 
    --一 建立表
    create table ZH_TEST

       ID NUMBER not null, 
       NAME VARCHAR2(20)
    ) --二 建立sequence
    create sequence ZH_AUTOINC 
    minvalue 1 
    start with 1 
    increment by 1 
    nocache;--三 建立触发器
    create or replace trigger INSERT_FOR_AUTOINC
       before insert on ZH_TEST   
       for each row 
    declare 
      -- local variables here 
    begin 
       select ZH_AUTOINC.nextval into:new.ID from dual;
    end insert_for_autoinc;--四 用insert语句测试
    insert into ZH_TEST(NAME) values ('z5');这样你就可以不用每次插入数据的时候,都指定ID值为ZH_AUTOINC.nextval了
      

  2.   

    没有 auto_increment  这样的只有序列建立触发器或每次insert 
    或 使用sys_guid()产生一串随即字符
      

  3.   

    没有auto_increment
    要实现只能用sequence+trigger
    用法参照1楼