Home » SQL & PL/SQL » SQL & PL/SQL » Piping results of an sql insert into a 2nd insert statement (Oracle 10g)
Piping results of an sql insert into a 2nd insert statement [message #316123] Wed, 23 April 2008 18:04 Go to next message
orafaqBrowser
Messages: 3
Registered: April 2008
Junior Member
Hi,

I am attempting to create a script such that I can use the results from my first insert statement as input to my second insert statement.

For example -
insert into table1 (col2,col3) values ('b','c');
[col1 is automatically populated by a sequence value]

insert into table2 (colA,colB,colC) values ('x','&col1','z');
[where &col1 is the value generated from the above statement]


The temporary solution I'm working with at the mo is to manually run a select statement to obtain the newly inserted value into col1 and then running the second insert statement.

There must be a more elegant way of achieving this, but it's eluded me so far! Can anyone provide any suggestions?

Thanks,
Re: Piping results of an sql insert into a 2nd insert statement [message #316125 is a reply to message #316123] Wed, 23 April 2008 18:05 Go to previous messageGo to next message
BlackSwan
Messages: 25037
Registered: January 2009
Location: SoCal
Senior Member
> Can anyone provide any suggestions?
INSERT ....... RETURNING ......
Re: Piping results of an sql insert into a 2nd insert statement [message #316130 is a reply to message #316125] Wed, 23 April 2008 18:33 Go to previous messageGo to next message
orafaqBrowser
Messages: 3
Registered: April 2008
Junior Member
Many thanks. I'll give that a try.
Re: Piping results of an sql insert into a 2nd insert statement [message #316374 is a reply to message #316125] Thu, 24 April 2008 17:41 Go to previous message
orafaqBrowser
Messages: 3
Registered: April 2008
Junior Member
That worked a treat. Thanks again.
Previous Topic: SQL: Listing/Showing functions created by "CREATE function"?
Next Topic: ORA-00904: : invalid identifier
Goto Forum:
  


Current Time: Mon Dec 05 06:36:11 CST 2016

Total time taken to generate the page: 0.07642 seconds