Program to perform Simple Switch CASE in PL/SQL
In this Switch case is same as in C language. Only the difference in they worked.
Syntax:
DECLARE
<DECLARATION SECTION>
BEGIN
CASE
WHEN SEARCHED_CONDITON1 THEN STATEMENT'S;
WHEN SEARCHED_CONDITON2 THEN STATEMENT'S;
ELSE STATEMENT;
END CASE;
END;
Syntax:
DECLARE
<DECLARATION SECTION>
BEGIN
CASE
WHEN SEARCHED_CONDITON1 THEN STATEMENT'S;
WHEN SEARCHED_CONDITON2 THEN STATEMENT'S;
ELSE STATEMENT;
END CASE;
END;
Program:
DECLAREGRADE CHAR(1);
BEGIN
GRADE:=&GRADE;
CASE GRADE
WHEN '0' THEN DBMS_OUTPUT.PUT_LINE('OUTSTANDING');
WHEN 'A' THEN DBMS_OUTPUT.PUT_LINE('EXCELLENT');
WHEN 'B' THEN DBMS_OUTPUT.PUT_LINE('GOOD');
WHEN 'C' THEN DBMS_OUTPUT.PUT_LINE('SATISFACTORY');
ELSE DBMS_OUTPUT.PUT_LINE('INVALID GRADE');
END CASE;
END;
Output:
Note: Always give single cottation mark while input.