Case
set serveroutput on;
DECLARE
a NUMBER :=65;
b NUMBER :=2;
arth_operation VARCHAR2(20) :='MULTIPLY';
BEGIN
dbms_output.put_line('Program started.' );
CASE (arth_operation)
WHEN 'ADD' THEN
dbms_output.put_line('Addition of the numbers are: '|| a+b );
WHEN 'SUBTRACT' THEN
dbms_output.put_line('Subtraction of the numbers are: '||a-b );
WHEN 'MULTIPLY' THEN
dbms_output.put_line('Multiplication of the numbers are: '|| a*b);
WHEN 'DIVIDE' THEN
dbms_output.put_line('Division of the numbers are:'|| a/b);
ELSE
dbms_output.put_line('No operation action defined. Invalid operation');
END CASE;
dbms_output.put_line('Program completed.' );
END;
--Searched case
DECLARE
a NUMBER :=70;
b NUMBER :=2;
arth_operation VARCHAR2(20) :='DIVIDE';
BEGIN
dbms_output.put_line('Program started.' );
CASE
WHEN arth_operation = 'ADD' THEN
dbms_output.put_line('Addition of the numbers are: '||a+b );
WHEN arth_operation = 'SUBTRACT' THEN
dbms_output.put_line('Subtraction of the numbers are: '|| a-b);
WHEN arth_operation = 'MULTIPLY' THEN
dbms_output.put_line('Multiplication of the numbers are: '|| a*b );
WHEN arth_operation = 'DIVIDE' THEN
dbms_output.put_line('Division of the numbers are: '|| a/b );
ELSE
dbms_output.put_line('No operation action defined. Invalid operation');
END CASE;
dbms_output.put_line('Program completed.' );
END;
Comments