PL/SQL: Conditions Cheat Sheet

IF-THEN Statement
IF condition THEN  
   Statement; 
END IF; 
IF-THEN-ELSE Statement
IF condition THEN 
   Statement1;  
ELSE  
   Statement2; 
END IF;
IF-THEN-ELSIF Statement
IF(boolean_expression 1)THEN  
   Statement1; -- Executes when the boolean expression 1 is true  
ELSIF( boolean_expression 2) THEN 
   Statement2;  -- Executes when the boolean expression 2 is true  
ELSIF( boolean_expression 3) THEN 
   Statement3; -- Executes when the boolean expression 3 is true  
ELSE  
   Statement4; -- executes when the none of the above condition is true  
END IF; 
CASE Statement
CASE selector 
   WHEN 'value1' THEN Statement1; 
   WHEN 'value2' THEN Statement2; 
   WHEN 'value3' THEN Statement3; 
   ... 
   ELSE Sn;  -- default case 
END CASE;
Searched CASE Statement
CASE 
   WHEN selector = 'value1' THEN Statement1; 
   WHEN selector = 'value2' THEN Statement2; 
   WHEN selector = 'value3' THEN Statement3; 
   ... 
   ELSE Sn;  -- default case 
END CASE; 
Nested IF-THEN-ELSE Statements
IF( boolean_expression 1)THEN 
   -- executes when the boolean expression 1 is true  
   IF(boolean_expression 2) THEN 
      -- executes when the boolean expression 2 is true  
      sequence-of-statements; 
   END IF; 
ELSE 
   -- executes when the boolean expression 1 is not true 
   else-statements; 
END IF; 

Leave a Reply

Your email address will not be published. Required fields are marked *