Control structure: – Control structures are used to modify the flow of program. Control structures give processing capability to a program. Statements of control structure are divided into three different categories. They are conditional control statement, unconditional control statement and iterative control statement.

Conditional control statement: – The conditional control statements are used to change flow of program conditionally. In this category, the control structure divided into three different types of statements. They are –

  1. If-then statement
  2. If-then-else statement
  3. If-then-elsif statement.

If-then statement: – if-then is a single branching statement. The flow of control is executed according to true condition. If condition is false, control jump out of the branch. Syntax of the if-then statement is –

if <Test Expression> Then
                Statements
end if;

If-then-else statement: – This statement is used for two-way branching. The else keyword is used to provide alternate sequence of statement, if condition is not true. Syntax of the if-then-else statement is –

if <Test Expression> Then
                Statements
else
                Statements
end if;

If-then-elsif statement: – This type of conditional branching statement is called multiple testing or multiple ways of branching. More than one test expressions are used with this statement but only one branch is executed from beginning which is conditionally true and then control jump out of the branch. If no any conditions are true, statement execute else branch. Syntax of the if-the-elsif statement is –

if <Test Expression> Then
                Statements
elsif <Test Exprossion> Then
                Statements
                _ _ _ _ _
                _ _ _ _ _
else
                Statements
end if;

unconditional control statement: – This type of statements is used to control of flow without any condition. Only one statement available in PL/SQL to control flow without any condition. The go to statement is used to flow control without any condition. Syntax of the go to statement is –

go to <label code>;

iterative control statement: – The iterative statements are used to repeat and execute one or more statements repeatedly. There are three statement available in this category. They are for-loop, while-loop and loop-exit.

For-loop: – The for-loop statement is used to iterates over a specified range of integers. Number of iteration is known as advance. Syntax of the for-loop statement is –

For <Variable Name> in <Initial Value>..<Final Value> loop 
Statements
End loop;

While-loop: – The while loop is a conditional looping statement. Number of iteration depend on the condition. If condition is true, loop continued and if condition is false, loop is terminated. Because condition is tested at the beginning of the statement, it is called top tested loop. Syntax of the while-loop is –

While <Test Expression> loop
Statements
End loop;

Loop-exit: – This statement is also a conditional repetitive statement. But condition is tested at the end of block, it is called bottom tested loop. Syntax of the loop-exist statement is –

Loop
Statements
Exit when <Test Expression>
End loop;
Advertisements