Construction of Oracle Loops
https://www.computersprofessor.com/2016/04/construction-of-oracle-loops.html
1. ONE-WAY
IF:
The
if commands are used for selection or decisions.
Syntax:
IF <condition> then
………………………..
…………………………
Statements
……………………
…………………….
END IF
IF <condition> then
………………………..
…………………………
Statements
……………………
…………………….
END IF
2.TWO
WAY IF:
IF
the condition is true it perform some set of statements if it is false it performs another set of statements
this is also used for selection & decision making
SYNTAX:
IF <CONDITION>then
…………………………
…………………………
STATEMENT -1
…………………………
…………………………
Else
……………………
……………………
STATEMENT-2
………………….
…………………
END IF
3.MULTI
–WAY IF:
When
a series of decisions are involved we may to use more than one –else if statements is nested as follows,
SYNTAX:
IF <condition > then
……………………………
……………………….
IF –ELSE <CONDITION>then
…………………
……………..
IF- ELSE (CONDITION) then
……………..
END –IF
ITERATION
LOOPS:
FOR
LOOP:
It
is used to repeat (or) execute a set of
statements for a specified a number of times
by giving the starting number & ending number. A variable is used
for starting number & increment itself
for every iteration on the loop & exists when the
number exceeds the given number.
The loop structure is used to execute a set of statements repeatedly.
The
statements repeatedly executed must be enclosed with in the loop & we
should use the END0- if command at last .The loop must also contain the
statements to be executed to execute the loop.
SYNTAX: LOOP
……………
END-LOOP
WHILE-
LOOP:
It
is also similar to for loop & it also has the loop construction, while loop
checks the condition initially to enter into the loop.
FOLLOWING STEPS ARE USED TO WRITE AND EXECUTE A PROGRAM
1. AT SQL PROMPT TYPE:
EDIT <FILE- NAME>
2. TYPE A PROGRAM
DECLARE
BEGIN
EXCEPTION
END;
3. SAVE the file ( file menu – save option)
4. Close editor , so that you will be back to SQL prompt
5. To execute the program use the following steps
SQL >= start <file –name> press enter
Or
SQL> @ <file-name>
Or
SQL> @ <file-name>