Conditional Control in DBMS

If we need to check for some condition and based on the condition we need to display the column values, then we can use IF conditions in the SELECT statement.

SELECT STD_ID, 
	STD_NAME,
	IF STD_MARK>=80 
	  THEN ‘A’
	ELSIF STD_MARK >=60 AND STD_MARK

This conditional IF statement works similar to any other language. We can even use them in the PL/SQL code in the same manner.

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