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!
Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.
update expertise_areas set expertise_level = case expertise_level when 'user' then 'appretissance' else expertise_level end case
Scuze me, I forgott the code
What is the error you are receiving??? Isn't it worth to post the actual error.
Your syntax is incorrect and I think the logic is also incorrect at the same time.
Without the Where clause you will end up updating all the non-matching rows to NULL.
SQL> update expertise_areas 2 set expertise_level = 3 case (when expertise_level='user') then (expertise_level='appretissance') 4 end case ; case (when expertise_level='user') then (expertise_level='appretissance') * ERROR at line 3: ORA-00907: missing right parenthesis SQL> select * from expertise_areas; EXPERTISE_LEVEL ------------------------------ user test appretissance SQL> update expertise_areas 2 set expertise_level = 3 case when expertise_level='user' then 'appretissance' 4 end ; 3 rows updated. SQL> select * from expertise_areas; EXPERTISE_LEVEL ------------------------------ appretissance
If you want to update all the values of "expertise_level = 'user'" to "appretissance" then you should be using something like this:
SQL> rollback; Rollback complete. SQL> update expertise_areas 2 set expertise_level = 'appretissance' 3 where expertise_level='user' ; 1 row updated. SQL> select * from expertise_areas; EXPERTISE_LEVEL ------------------------------ appretissance test appretissance SQL>
Hi Jeneesh,
Did you try to execute the Update statement you posted?
SQL> update expertise_areas 2 set expertise_level = 3 case expertise_level when 'user' then 'appretissance' 4 else expertise_level 5 end case; end case * ERROR at line 5: ORA-00933: SQL command not properly ended
Just take a look at this nested case syntax based on emp table of SCOTT schema......
SQL> select ename,sal from emp order by 1; ENAME SAL ---------- --------- ALLEN 1600,00 BLAKE 2850,00 CLARK 2450,00 FORD 3000,00 JAMES 950,00 JONES 2975,00 KING 5000,00 MARTIN 1250,00 MILLER 1300,00 SMITH 800,00 TURNER 1500,00 WARD 1250,00 12 rows selected SQL> SQL> update emp set sal=case when sal<=1000 then 0 else case when sal>=1000 and sal<=1500 then 1 2 else case when sal>1500 and sal<=2500 then 2 end end end 3 / 12 rows updated SQL> SQL> select ename,sal from emp order by 1; ENAME SAL ---------- --------- ALLEN 2,00 BLAKE CLARK 2,00 FORD JAMES 0,00 JONES KING MARTIN 1,00 MILLER 1,00 SMITH 0,00 TURNER 1,00 WARD 1,00 12 rows selected
Greetings... Sim