× 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 - Control Statements


PL/SQL - Control Statements
Control Statements are used to ramdom execution of the program .In PLSQL lamguage these are classified into following types.

1.Conditional Statements
2.Looping Statements
3.Unconditional Statements
Conditional Statements
Conditional statements are used check the condition whether it is true or false.
In PLSQL language these opeatrs are classified into following types.

1.IF - THEN statement
2.IF-THEN-ELSE statement
3.IF-THEN-ELSIF statement
4.nested IF-THEN-ELSE
5.Case statement
6.Searched CASE statement

IF - THEN statement
'if- then' is a keyword in PLSQL language .Which is used to execute one block of statements by negleting some other statements.
Syntax:
if(Condition) then
...
...
...
end if;
In the above syntax 'if' condition is true the statements of 'if' block is execute.'if' the condition is false program terminated.
Example #1
DECLARE 
   a number(2) := 10; 
BEGIN 
   IF( a < 20 ) THEN 
      
      dbms_output.put_line('a is less than 20' ); 
   END IF; 
   dbms_output.put_line('value of a is : ' || a); 
END; 
/


Example #2
DECLARE 
   c_id customers.id%type := 1; 
   c_sal  customers.salary%type; 
BEGIN 
   SELECT  salary  
   INTO  c_sal 
   FROM customers 
   WHERE id = c_id; 
   IF (c_sal <= 2000) THEN 
      UPDATE customers  
      SET salary =  salary + 1000 
         WHERE id = c_id; 
      dbms_output.put_line ('Salary updated'); 
   END IF; 
END; 
/

Key Points

  • PL/SQL - Control Statements
  • Image