Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: last inserted id
"almir" <a.kazazic_at_medienhaus.co.at> wrote in message
news:GGlv6.44086$Y8.1889039_at_news.chello.at...
> i am using oracle trhough php, and have a extra function for inserting new
> rows, up to now with single parametar sql statement, that always returns
> last inserted id depending of database in mysql is mysql_inserted_id or in
> sql server select @identity ,
> that was easy but now in oracle how can i achive that i have about 40
> tables( with their triggers and sequencies) my only idea in moment is to
> take the name of table from statement (third word) and give that function
> parametar from now on , that would be ignored on other RDBMS, and before i
> make commit in my insert function i would do select max(id_name) from
3_word
> and then make commit , this should do but is somehow realy stupid and i
> would like to change it , is there a beter why of achieving this
>
> thanks
> almir
>
>
On Oracle 8.0 and before you would use
select <sequence>.nextval
into <somevariable>
from dual;
insert into foo values (<somevariable>) etc.
On Oracle 8i you could use the returning clause of the insert statement and skip the first step, replacing <somevariable> with <sequence>.nextval. So no need for max, which is impossible on a sequence anyway.
Hth,
Sybrand Bakker, Oracle DBA Received on Sun Mar 25 2001 - 07:37:04 CST
![]() |
![]() |