Case Statement in DBMS

Case statement is also similar to conditional control. We can use this in the same way.

SELECT STD_ID, 
	STD_NAME,
	CASE 
		WHEN STD_MARK>=80    THEN ‘A’
		WHEN STD_MARK >=60 AND STD_MARK<80    THEN ‘B’
		ELSE ‘C’
	END CASE AS GRADE
FROM STUDENT s, MARKS m
WHERE s.STD_ID = m.STD_ID;

It can be used in PL/SQL blocks too.

DECLARE
	v_emp_id EMPLOYEE.EMP_ID%TYPE: =1212;
BEGIN
   CASE 
	WHEN v_emp_id = 12121 THEN
     	 	DBMS_OUTPUT.PUT_LINE (‘Same employee ID is entered’);   
	 ELSE
     		 DBMS_OUTPUT.PUT_LINE (‘Different employee ID is entered’);
Translate »