× 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

IF-THEN-ELSIF statement


IF-THEN-ELSIF statement
'IF-THEN-ELSIF' is keyword in PLSQL language which is used to execute one block of statemnets amoung the multiple blocks.
Syntax:
IF(Condition 1)THEN  
   ...
   ...
ELSIF( Condition 2) THEN 
   ...
   ...
ELSIF( Condition 3) THEN 
   ...
   ...
...
...
ELSE  
   ...
   ...

END IF; 
Example #1
DECLARE 
   c_id customers.id%type := 2; 
   c_sal  customers.salary%type;
BEGIN 
   SELECT salary INTO c_sal
   FROM customers
   WHERE id= c_id; 
if( c_sal>0 and c_sal<=10000) then
   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;
else
dbms_output.put_line('invalid details');
end if;
 
END; 
/  



Key Points

  • IF-THEN-ELSIF statement
  • Image