Oracle PL SQL 4
Oracle PL SQL 4
PL/SQL: if Statement
• If the result of the condition is TRUE then certain specified action will be performed
otherwise if it is FALSE then no action is taken and the control of program will just move out
of the if code block.
• An if statement lets your program know whether or not it should execute a block of code.
• Example:
• if <test_condition> then
• body of action
• end if;
CASE selector
...
else statement;
end CASE;
Example:
DECLARE
BEGIN
CASE grade
END CASE;
END;
• This allows to specify two statements or two set of statements, dependent on a condition
such that when the condition is true then one set of statements is executed.
if <test_condition> then
else
end if;
Use loop structures: FOR and WHILE
• It provides a way of repeating a particular part of any program or any code statement as
many times as required.
While Loop
• It is an entry-controlled loop
• Before entering in a while loop first the condition is tested, if the condition is TRUE the
statement or a group of statements get executed.
• If the condition is FALSE the control will move out of the while loop.
<action>
END LOOP;
• It provides a way of repeating a particular part of any program or any code statement as
many times as required.
While Loop
• It is an entry-controlled loop
• Before entering in a while loop first the condition is tested, if the condition is TRUE the
statement or a group of statements get executed.
• If the condition is FALSE the control will move out of the while loop.
<action>
END LOOP;
• This loop is used when some statements in PL/SQL code block are to be repeated for a fixed
number of times.
• Define a counter variable which decides how many time the loop will be executed based on a
starting and ending value provided at the beginning of the loop.
• The for loop automatically increments the value of the counter variable by 1 at the end of
each loop cycle.
statement to be executed
END LOOP;
Practice exercises
https://devgym.oracle.com/pls/apex/dg/workout/case-in-pl-sql.html
https://youtu.be/4qJJxQuHLC4?si=KgeRz_XAZqKRPJFq
To download HR schema