Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: how to know the latest sequence number?
Hi,
you could also use the "returning into" clause of the INSERT
statement as you can see below:
<SCRIPT>
drop sequence effe_seq;
drop table effe_table;
create sequence effe_seq;
create table effe_table (c1 number);
variable a number
variable b number
begin
insert into effe_table (c1) values (effe_seq.nextval) returning c1 into
:a;
end;
/
insert into effe_table (c1) values (effe_seq.nextval) returning c1 into :b;
print a
print b
</SCRIPT>
This returns following output in sqlplus:
Reeks is verwijderd. Tabel is verwijderd. Reeks is aangemaakt. Tabel is aangemaakt.
A
1
B
2
Regards,
Andre van Winssen
"Bill Han" <billxhan_at_hotmail.com> wrote in message
news:t5x18.7616$467.301188_at_news2.calgary.shaw.ca...
> Hi everyone,
>
> I use a sequence's next value as table's primary key to append a record.
> After that, how can I know what that number is?
>
> insert into Contact (contact_id, contact_name)
> values (contact_seq.nextval, in_contact_name)
>
> then I want to know what is the contact_id I just used?
>
> Thanks,
> Bill
>
>
Received on Thu Jan 17 2002 - 04:16:41 CST