Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: id of last inserted row?
"Mark Harrison" <mh_at_pixar.com> a écrit dans le message de news: QMNzg.3453$uo6.2275_at_newssvr13.news.prodigy.com...
| I've got a table with an autoincremented identifier, as
| specified below (some cols truncated for brevity).
|
| I do something like
| insert into bar(name) values('mark');
|
| and I would like to get back the id that
| was just inserted for me.
|
| How can I do that?
|
| Many TIA!
| Mark
|
|
|
| REM FOO BAR
| CREATE TABLE "FOO"."BAR"
| ( "ID" NUMBER(20,0) NOT NULL ENABLE,
| "NAME" VARCHAR2(64 BYTE) NOT NULL ENABLE,
| CONSTRAINT "BAR_PK" PRIMARY KEY ("ID") ENABLE
| ) ;
| CREATE OR REPLACE TRIGGER "FOO"."INS_BAR" BEFORE INSERT ON BAR
| FOR EACH ROW
| BEGIN SELECT BAR_SEQ.nextval INTO :new.ID FROM dual; END;
| /
| ALTER TRIGGER "FOO"."INS_BAR" ENABLE;
| CREATE UNIQUE INDEX "FOO"."BAR_PK" ON "FOO"."BAR" ("ID")
| ;
|
| --
| Mark Harrison
| Pixar Animation Studios
Have a look at the "returning" clause of "insert" statement.
Regards
Michel Cadot
Received on Tue Aug 01 2006 - 14:26:06 CDT