Simple case demo : Case « PL SQL « Oracle PL / SQL






Simple case demo

 
-- read user input

set echo off
set define '&'
set verify off
set serveroutput on size 10000

prompt
accept NUM prompt 'Enter a single digit number : '
prompt

declare
  l_num number := #
begin
  case l_num
    when 1 then dbms_output.put_line('You selected one');
    when 2 then dbms_output.put_line('You selected two');
    when 3 then dbms_output.put_line('You selected three');
    when 4 then dbms_output.put_line('You selected four');
    when 5 then dbms_output.put_line('You selected five');
    when 6 then dbms_output.put_line('You selected six');
    when 7 then dbms_output.put_line('You selected seven');
    when 8 then dbms_output.put_line('You selected eight');
    when 9 then dbms_output.put_line('You selected nine');
    when 0 then dbms_output.put_line('You selected zero');
  end case;
end;
/




           
         
  








Related examples in the same category

1.Case conditions
2.Case with else
3.CASE WHEN statement with variable
4.CASE WHEN with constant
5.CASE not found while executing CASE statement
6.This CASE statement is labeled
7.CASE WHEN with comparison operator
8.Uses a NUMBER datatype as the selector
9.Output discount rate based on different category