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!

Combine select and update into single statement,without bind-variable

577433May 14 2007 — edited May 14 2007
I have a problem, that I think is not possible to solve the way I want to, but I just wanted to check before leaving the idea...

I am looking for a way to combine the select and the update statement into one single statement. This is what I wan't to achive: select some data, and update the data selected before returning them.

On this site http://www.psoug.org/reference/update.html I see that the following are possible:

var bnd1 NUMBER
var bnd2 VARCHAR2(30)
var bnd3 NUMBER

UPDATE employees
SET job_id ='SA_MAN', salary = salary + 1000,
department_id = 140
WHERE last_name = 'Jones'
RETURNING salary*0.25, last_name, department_id
INTO :bnd1, :bnd2, :bnd3;


I need to have this as a single statement, and cannot use bind-variables. So I was hoping that something like this could be possible:

UPDATE customer c
SET c.HAS_CREDIT ='1'
WHERE c.HAS_CREDIT = '0'
RETURNING c.CUSTOMER_NO, c.FIRSTNAME, c.LASTNAME
where c.HAS_CREDIT = '1'


But this doesn't compile, complaining of missing into (ORA-00925: missing INTO keyword). And even though I would like this to be possible because this would solve my current problem, I think it would be very confusing. For instance; would the where clause of the returning part be operating after the update or before?

Any comments or suggestions on how to get it work in a single statement, or should I just leave this path straight away?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 11 2007
Added on May 14 2007
3 comments
767 views