× PL/SQL - Overview PL/SQL - Basic Syntax PL/SQL - Data Types PL/SQL - Variables PL/SQL - Constants and Literals PL/SQL - Operators PL/SQL - Conditions PL/SQL -ifelse PL/SQL -elsif PL/SQL -nestedif PL/SQL -Case PL/SQL -Searched Case PL/SQL -Basic Loop PL/SQL -For Loop PL/SQL -While Loop PL/SQL - Strings PL/SQL - Arrays PL/SQL - Procedures PL/SQL - Functions PL/SQL - Cursors PL/SQL - Records PL/SQL - Exceptions PL/SQL - Triggers PL/SQL - Packages PL/SQL - Collections PL/SQL - Transactions PL/SQL - Date & Time PL/SQL - DBMS Output PL/SQL - Object Oriented
  • iconPLSQL Online Training In Andhra Pradesh and Telangana
  • icon9010519704

Opening Hours :7AM to 9PM

PL/SQL - Nested IF-THEN-ELSE Statements


PL/SQL - Nested IF-THEN-ELSE Statements
One if condition with in another if condition is known as nested if.
Syntax:
IF( Condition 1)THEN 
    ...
    ...
   IF(Condition 2) THEN 
    ...
    ...
   ELSE
     ....
     ....
   END IF; 
ELSE 
   ...
   ....
   
END IF; 
Example #1
DECLARE 
   c_id customers.id%type := 3; 
   c_sal  customers.salary%type; 
BEGIN 
   SELECT salary INTO c_sal
   FROM customers
   WHERE id= c_id;  
   if(c_sal>=1000 and c_sal<=2000) then
   update customers set salary=c_sal+100 where  id= c_id; 
  elsif(c_sal>=3000 and c_sal<=6000) then
   update customers set salary=c_sal+200 where  id= c_id; 
  elsif(c_sal>=7000 and c_sal<=10000) then
   update customers set salary=c_sal+500 where  id= c_id; 

   else
   update customers set salary=c_sal-1000 where  id= c_id; 
end if;
   
END; 
/  


Key Points

  • PL/SQL - Nested IF-THEN-ELSE Statements
  • Image