Oracle与SQL Server的@@IDENTITY
对应的是什么?
答案 0 :(得分:2)
鉴于Oracle没有标识列,您通常会为每个表创建一个序列,并使用该序列填充主键。假设您已经这样做了,您可以获取序列的currval
以获取当前会话的最近生成的序列值。
SQL> create table foo(
2 col1 number primary key,
3 col2 varchar2(10)
4 );
Table created.
SQL> create sequence foo_seq;
Sequence created.
SQL> ed
Wrote file afiedt.buf
1 create or replace trigger foo_trg
2 before insert on foo
3 for each row
4 begin
5 :new.col1 := foo_seq.nextval;
6* end;
SQL> /
Trigger created.
SQL> insert into foo( col2 )
2 values( 'foo' );
1 row created.
SQL> insert into foo( col2 )
2 values( 'bar' );
1 row created.
SQL> select foo_seq.currval
2 from dual;
CURRVAL
----------
2