[linux] Re: Last record in table
Robert Cordingley
cord na ragesoft.com
Pátek Leden 28 19:59:49 CET 2000
On Fri, 28 Jan 2000, Pedro Fradique da Silva wrote:
> After inserting a record I'm trying to retrieve the last record in a
> table(that would be the one I just inserted), so I can use one of its
> values in another insert.
> Is there a simple way to do it?
> How can I lock the database so that nothing is done between that first
> insert and the select?
Oh the answer is: don't do that...it hurts when you do that.
In oracle8i, if you're using PL/SQL, you can use the new "returning" clause
on an insert or update to retrieve some values from what just happened. If
you're trying to get back a sequence value, the better way to do it is to:
select mysequence.nextval from dual;
insert into foo ( new_id, new_data ) values ( <result from above>, 'data' );
Locking things manually in oracle is a Bad Thing unless you're absolutely sure
you know what you're doing. It's a bad idea...don't do it. If you think it's
a good idea, think again. Just don't do it. 8)
Robert
--
Don't forget! Abstracts are due January 25th 2000. Act now and make your
reservations for ODTUG 2000 -- the best conference of the new century! See
the website at http://www.odtug.com for full details.
--
Author: Robert Cordingley
INET: cord na ragesoft.com
Fat City Network Services -- (619) 538-5051 FAX: (619) 538-5051
San Diego, California -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru na fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-LINUX-L
(or the name of mailing list you want to be removed from). You may
also send the HELP command for other information (like subscribing).
Další informace o konferenci linux