Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: how to know the latest sequence number?

Re: how to know the latest sequence number?

From: Andre van Winssen \(andrew\) <andrew_at_info.nl>
Date: Thu, 17 Jan 2002 11:16:41 +0100
Message-ID: <3c46a489$0$226$4d4ebb8e@news.nl.uu.net>


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.

PL/SQL-procedure is geslaagd.
1 rij 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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US