Program to perform GOTO statement in PL/SQL


                        Program to perform GOTO statement in PL/SQL

    In PL/SQL GOTO statement is same as in C language.It move the control of the program to the place where goto label is created.

Syntax to create label: 
        <<label_name>>

Note: Do not terminate the label.

Call of GOTO :
      GOTO label_name;

Program: This program is to demonstrate GOTO statement.

DECLARE
 b int:=5;
 BEGIN
 <<loopstart>>
 WHILE B<10
 LOOP
   dbms_output.put_line('value if b:'||b);
    b:=b+1;
      IF B=7 THEN
      B:=B+1;
          GOTO LOOPSTART;
      END IF;
 END LOOP;
END;


Explanation: In this we have taken a variable b and initialized  it with 5. We want to skip the 7 for                           that we  have used goto statement and created label with name loopstart. And when                             the 7 is come in loop increase the value of b by 1 and call goto statement.

Output:
-----------
Output

Previous
Next Post »