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: Bill Han <billhan_at_seatech.bc.ca>
Date: Thu, 17 Jan 2002 17:28:28 GMT
Message-ID: <0RD18.36498$e4.8742157@news0.telusplanet.net>


Thanks Andre, this is a good way too.

Regards,
Bill

"Andre van Winssen (andrew)" <andrew_at_info.nl> wrote in message news:3c46a489$0$226$4d4ebb8e_at_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 - 11:28:28 CST

Original text of this message

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