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;
Program:
DECLARE
A INT:=&A;
B INT:=&B;
CH INT;
RESULT INT:=-99999;
BEGIN
DBMS_OUTPUT.PUT_LINE('Menu'||chr(10)||' 1 Addition'||chr(10)||' 2 Substraction'||chr(10)||' 3 Multiplication'||chr(10)||' 4 Division');
CH:=&CH;
DBMS_OUTPUT.PUT_LINE('Enter Your choice(1/2/3/4)'||CH);
DBMS_OUTPUT.PUT_LINE('A: '||A||CHR(10)||'B: '||B);
CASE
WHEN CH=1 THEN RESULT:=A+B;
WHEN CH=2 THEN RESULT:=A-B;
WHEN CH=3 THEN RESULT:=A*B;
WHEN CH=4 THEN RESULT:=A/B;
ELSE DBMS_OUTPUT.PUT_LINE('NO SUCH CASE');
END CASE;
IF RESULT !=-99999 THEN
DBMS_OUTPUT.PUT_LINE('RESULT:'||RESULT);
END IF;
END;
Explanation: In this program we have taken two number as input and then perform operation as per the user choice. and we assume that the result never equal to -99999. If it is equal to that value it then mean that user have entered wrong choice.