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!

Update multiple rows using CASE WHEN

Hawk333Sep 12 2013 — edited Sep 12 2013

I have the table ACCOUNT of structure as follow: 

ACCOUNT_IDACCOUNT_STATUS
0044607212
0420562915
6012720653

I need to update the three rows at once using one SELECT statement such that, the second column will be 5, 3, 2 respectively.
I used the following query but seems there is something missing

UPDATE ACCOUNT
SET ACCOUNT_STATUS = CASE  
WHEN ACCOUNT_STATUS = '004460721' THEN 5 
WHEN ACCOUNT_STATUS = '042056291' THEN 3 
WHEN ACCOUNT_STATUS = '601272065' THEN 2 
WHERE ACCOUNT_ID IN ('004460721','042056291','601272065') 

 

My question, is this way correct? if no, can I use CASE WHEN statement and how or I only have choice of using SUB-SELECT to acheive that in one statement?

This post has been answered by Purvesh K on Sep 12 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 10 2013
Added on Sep 12 2013
14 comments
1,190 views