The AskTOM team is taking a break over the holiday season, so we're not taking questions or responding to comments. Please have a happy and safe festive season and as always, thanks for being a member of the AskTOM community.
Thanks for the question.
Asked: June 28, 2006 - 9:41 pm UTC
Last updated: June 29, 2006 - 1:16 pm UTC
Version: 9.2
Viewed 1000+ times
A reader, June 29, 2006 - 12:25 pm UTC
Tom, Sorry I didn't provide the code previously. This was the scenario I was interested in. CASE "Statement" SQL> declare 2 v_color vachar2(20) := 'BLUE'; 3 result varchar2(20); 4 begin 5 case 6 when v_color = 'RED' then result := 'Code RED'; 7 when v_color = 'WHITE' then result := 'Code WHITE'; 8 end case; 9 dbms_output.put_line(nvl(result,'Code BLUE')); 10 end; 11 / declare * ERROR at line 1: ORA-06592: CASE not found while executing CASE statement ORA-06512: at line 5 SQL> declare 2 v_color vachar2(20) := 'BLUE'; 3 result varchar2(20); 4 begin 5 case 6 when v_color = 'RED' then result := 'Code RED'; 7 when v_color = 'WHITE' then result := 'Code WHITE'; 8 else NULL; 9 end case; 10 dbms_output.put_line(nvl(result,'Code BLUE')); 11 end; 12 / Code BLUE PL/SQL procedure successfully completed. Case "Expression" SQL> declare 2 v_color vachar2(20) := 'BLUE'; 3 result varchar2(20); 4 begin 5 result := 6 case 7 when v_color = 'RED' then 'Code RED' 8 when v_color = 'WHITE' then 'Code WHITE' 9 end; 10 dbms_output.put_line(nvl(result,'Code BLUE')); 11 end; 12 / Code BLUE PL/SQL procedure successfully completed. Thanks again.
A reader, June 29, 2006 - 1:44 pm UTC
I agree, however I was concerned with the need for an ELSE or an exception handler in one and not the other. SQL> declare 2 v_color vachar2(20) := 'BLUE'; 3 result varchar2(20); 4 begin 5 case 6 when v_color = 'RED' then result := 'Code RED'; 7 when v_color = 'WHITE' then result := 'Code WHITE'; 8 else NULL; 9 end case; 10 dbms_output.put_line(nvl(result,'Code BLUE')); 11 end; 12 / Code BLUE PL/SQL procedure successfully completed. ELSE (or an exception handler) is required above, or I receive the following: SQL> declare 2 v_color vachar2(20) := 'BLUE'; 3 result varchar2(20); 4 begin 5 case 6 when v_color = 'RED' then result := 'Code RED'; 7 when v_color = 'WHITE' then result := 'Code WHITE'; 8 end case; 9 dbms_output.put_line(nvl(result,'Code BLUE')); 10 end; 11 / declare * ERROR at line 1: ORA-06592: CASE not found while executing CASE statement ORA-06512: at line 5 However, it what the documentation labels a CASE "Expression", an ELSE or exception handler isn't required. SQL> declare 2 v_color vachar2(20) := 'BLUE'; 3 result varchar2(20); 4 begin 5 result := 6 case 7 when v_color = 'RED' then 'Code RED' 8 when v_color = 'WHITE' then 'Code WHITE' 9 end; 10 dbms_output.put_line(nvl(result,'Code BLUE')); 11 end; 12 / Code BLUE PL/SQL procedure successfully completed.
Donat Callens, September 20, 2007 - 7:42 am UTC
Share and learn SQL and PL/SQL; free access to the latest version of Oracle Database!
Classes, workouts and quizzes on Oracle Database technologies. Expertise through exercise!