Mega Code Archive

 
Categories / Oracle PLSQL / PL SQL
 

Use when inside case

SQL> SQL> -- switch case SQL> SQL> SQL> declare   2    l_num number := 7;   3  begin   4    case l_num   5      when 1 then dbms_output.put_line('You selected one');   6      when 2 then dbms_output.put_line('You selected two');   7      when 3 then dbms_output.put_line('You selected three');   8      when 4 then dbms_output.put_line('You selected four');   9      when 5 then dbms_output.put_line('You selected five');  10      when 6 then dbms_output.put_line('You selected six');  11      when 7 then dbms_output.put_line('You selected seven');  12      when 8 then dbms_output.put_line('You selected eight');  13      when 9 then dbms_output.put_line('You selected nine');  14      when 0 then dbms_output.put_line('You selected zero');  15      --else dbms_output.put_line('You selected more than one digit...');  16    end case;  17  end;  18  / You selected seven PL/SQL procedure successfully completed. SQL>