Identifying control structures
IF-ELSIF-ELSE: This statement allows you to control structure to execute a sequence of statements conditionally.
LOOP-END LOOP: This statement allows you to execute a sequence of statements multiple times.
EXIT: This statement allows you to exit from a loop immediately.
EXIT-WHEN: This statement allows you to exit a loop when the given condition is met.
WHILE-LOOP: This statement allows you to execute a sequence of statements while the given condition is
FOR-LOOP: This statement allows you to execute a sequence of statements for the given number of times.
Searched CASE Expression
A searched CASE expression lets you test different conditions instead of comparing a single expression to various values. It has the form shown in Example 4-1.
A searched CASE expression has no selector. Each WHEN clause contains a search condition that yields a BOOLEAN value, so you can test different variables or multiple conditions in a single WHEN clause.
Example 4 - 1 Using a Search Condition with a CASE Statement
2 grade CHAR(1) := 'B';
3 appraisal VARCHAR2(120);
4 id NUMBER := 8429862;
5 attendance NUMBER := 150;
6 min_days CONSTANT NUMBER := 200;
8 FUNCTION attends_this_school (id NUMBER)
9 RETURN BOOLEAN IS
11 RETURN TRUE;
15 appraisal :=
17 WHEN attends_this_school(id) = FALSE
18 THEN 'Student not enrolled'
19 WHEN grade = 'F' OR attendance < min_days
20 THEN 'Poor (poor performance or bad attendance)'
21 WHEN grade = 'A' THEN 'Excellent'
22 WHEN grade = 'B' THEN 'Very Good'
23 WHEN grade = 'C' THEN 'Good'
24 WHEN grade = 'D' THEN 'Fair'
25 ELSE 'No such grade'
28 ('Result for student ' || id || ' is ' || appraisal);
Result for student 8429862 is Poor (poor performance or bad attendance)
PL/SQL procedure successfully completed.