Willie Cheng
Willie Cheng

Reputation: 8263

How to update multi-rows in ORACLE with C# at once(one time IO) or it isn't impossible to happen

How to update data with difference condition and set,
it will be under one time Input and Output For example as following

Update set column1='1' where id=10;
Update set column1='2' where id=20;
Update set column1='3' where id=30;
   ......
Update set column1=N where id=N;

Please do me a favor to do this problem

PS: it is / isn't impossible to happen ???

Upvotes: 2

Views: 123

Answers (1)

Utsav
Utsav

Reputation: 8143

Edit: Simplified the query little more.

And as mentioned in the comment, you should try running it on test data first before running on actual data. Or make sure your session doesn't auto commit the transaction and then run update/delte and after checking, rollback/commit the transaction.

Also as a best practice, run the where clause with select to see how many/what rows are getting returned.

update table
 set column1 = (case id
                when 10 then '1'
                when 20 then '2'
                when 30 then '3' 
                end)
    where id in (10,20,30)

Previous:

Try something like below

 update table
 set column1 = (case when id=10 then '1'
                when id=20 then '2'
                when id=30 then '3' 
                end)
    where id in (10,20,30)

Upvotes: 2

Related Questions