Case block in PL/SQL.

Case: It is also a conditional control statement and used to create branches in the program.
syntax:

CASE ( Expression)
WHEN 'value 1' THEN
            ............block.....
WHEN 'value 2' THEN
            ............block.....
WHEN 'value 3' THEN
            ............block.....
ELSE
            ..............block...
END CASE;

OR

CASE 
WHEN (Expression) THEN
            ......block.....

WHEN (Expression) THEN
            ......block.....
WHEN (Expression) THEN
            ......block.....
WHEN (Expression) THEN
            ......block.....
ELSE
            ..........block...
END CASE;


Example:

SET SERVEROUTPUT ON
DECLARE
        i integer;
BEGIN
        DBMS_OUTPUT.PUT_LINE('ENTER AN INTEGER');
        i:=&i;
        CASE i
        WHEN 1 then
            DBMS_OUTPUT.PUT_LINE('one');
        WHEN 2 then
            DBMS_OUTPUT.PUT_LINE('two');
        WHEN 3 then
        DBMS_OUTPUT.PUT_LINE('three');
        ----------"------------------"--------------------
        ---------"------------------"-------------------
        WHEN 10 then
            DBMS_OUTPUT.PUT_LINE('ten');
        ELSE
            DBMS_OUTPUT.PUT_LINE('not match');
END CASE;
END;

Comments

Popular posts from this blog

Introduction to Python.

Decision Making Statement.