Construction of Oracle Loops

1. ONE-WAY IF:

The if commands are used for selection or decisions.

Syntax:

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
……………………………
<ACTION>(CAN BE MANY STATEMENTS)
……………………….
IF –ELSE <CONDITION>then
…………………
<ACTION>(CAN BEMANY STATEMENTS)
……………..
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.

SYNTAX:  
  
For Loop Syntax
LOOP

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.


The pl/sql block can be created  by using an editor like note pad, if you want to terminate a pl/ sql block  within a line by itself press ENTER KEY(¿).

FOLLOWING STEPS ARE USED TO WRITE AND EXECUTE A PROGRAM

1. AT SQL PROMPT TYPE:

EDIT <FILE- NAME>  TO OPEN THE NOTE PAD EDITOR

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>

Related

Oracle 8680182871067041399

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item