Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Is there a "returning" clause for insert statement?

plsql noviceJan 30 2008 — edited Jan 30 2008
I'm trying to fix an order for customer manually, but our software uses hibernate to generate a random OID for each record, so I made up a sql statement like this:

update orderTable set orderSubTable1ID =
(insert into orderSubTable1 (orderSubTable1ID)
values (hibernate_sequence.nextval)
returning orderSubTable1ID)
where orderTableID = 123456;

orderSubTable1ID is a column that exists in both orderTable and orderSubTable1, so it functions like a FK. Whenever a record is generated in orderTable, an order
is also generated in orderSubTable1 and its ID inserted back into orderTable.
However, once in a while (the order I'm fixing) a record is not created in orderSubTable1, so I need to manually insert a record and put back its OID into orderTable.

The above sql gave me this error msg:
ORA-00925: missing INTO keyword
the * is pointing at the returning clause.

My colleague suggests the following:
Step 1:
select hibernate_sequence.nextval from dual;
Step 2:
insert into orderSubTable1 (orderSubTable1ID,....) values
(result from Step 1, ......);
Step 3:
update orderTable set orderSubTable1ID = [result from Step 1]
where orderTableID = 123456;

I'm not sure if the delay between Step 1 and Step 3 would cause any problems or not, and would like to have this task integrated into 1 statement. Anyone has idea how to do it? Many thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 27 2008
Added on Jan 30 2008
1 comment
562 views