Oracle Update and Return a Value

2019-01-25 20:38发布

问题:

I am having a Update Statement on a large volume table. It updates only one row at a time.

Update MyTable
Set Col1 = Value
where primary key filters

With this update statement gets executed I also want a value in return to avoid a Select Query on a same table to save resources. What will be my syntax to achieve this?

回答1:

You can use the RETURNING keyword.

Update MyTable
Set Col1 = Value
where primary key filters
returning column1,column2...
into variable1,variable2...


回答2:

If you are sure that it updates only one row, write same filter for a select query, like:

SELECT * FROM  MyTable
where primary key filters