Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.tools -> Re: JDBC PreparedStatements and Oracle sequences
If you need to get the next sequence number you can use a statement like
select last_number
from user_sequences
where sequence_name = 'mysequence';
do a desc on the table and have a look;
You do need to be a little careful with last_number though so look into
how it works and how nextval and currval.
select mysequence.currval from dual will also do it but you have to have done a nextval before you can access a currval.
I'm not sure I'd wan't to do this in the way you describe although there are sure to be some legitimate reasons to do it. I'd be inclined to insert the record first using mysequnce.nextval in the insert statement and then query the column you've used the sequence for to get the value. That way you get your sequence number and you've checked that the record has been entered.
Hope I've been of some help.
regards
Paul
In article <93knh6$mh2$1_at_nntp6.u.washington.edu>,
"Chuck" <cabenson_at_u.washington.edu> wrote:
> I am taking data from a form in a Java app and populating an Oracle
table
> through a JDBC connection. Before I insert a new record through the
Java
> app, I need to know what the current value of the sequence is in
Oracle
> (mysequence.currval).
>
> So, the app needs to query the database for the current sequence value
in
> the database and then use this value to do a record insertion from the
> application.
>
> Any suggestions on how to query the database for this value?
>
> Thanks,
> Chuck
>
>
Sent via Deja.com
http://www.deja.com/
Received on Thu Jan 11 2001 - 18:47:14 CST
![]() |
![]() |