sqlserver中有@@IDENTITY这样一个全局变量,作用是如果做了插入操作,那么这个变量会把插入这行的主键值存储下来,如果是插入多行数据,则只记录最后一行。
oracle中是否有@@IDENTITY变量这样的功能,或者有没有类似的解决方法。谢谢

解决方案 »

  1.   

    drop sequence tes_seq;
    -- Create sequence 
    --create sequence
    create sequence tes_seq
    minvalue 1
    maxvalue 999999999999999999999999999
    start with 1
    increment by 1
    cache 20;--test
    drop table mytest;
    create table mytest(sid varchar2(10),b varchar(10));
    insert into mytest values(tes_seq.nextval,'a');
    insert into mytest values(tes_seq.nextval,'b');
    insert into mytest values(tes_seq.nextval,'c');--result
    SQL> select * from mytest;
     
    SID        B
    ---------- ----------
    1          a
    2          b
    3          c
      

  2.   


    DECLEAR
    r ROWIDBEGININSERT  INTO MyTable(...) 
            VALUES(...) 
            RETURNING ROWID INTO r;SELECT * 
            FROM MyTable 
            WHERE ROWID = r;...END