-->

15 August 2020

PL/SQL GOTO Statement

  Asp.Net CS By Example       15 August 2020

 PL/SQL GOTO Statement  


 GOTO Statement : 

     The GOTO statement performs unconditional branching to another executable state‐ ment in the same execution section of a PL/SQL block. As with other constructs in the language, if we use GOTO appropriately and with care, our programs will be stronger for it..

 Local Variable : 

    The general format for a GOTO statement is:

 GOTO label_name 

    Where label_name is the name of a label identifying the target statement. This GOTO label is defined in the program as follows:
  << label_name >> 

     We must surround the label name with double enclosing angle brackets (<< >>). When PL/SQL encounters a GOTO statement, it immediately shifts control to the first exe‐ cutable statement following the label. Following is a complete code block containing both a GOTO and a label:
 BEGIN
     GOTO  second_output;
     DBMS_OUTPUT.PUT_LINE ('This line will never execute.');  
     <<second_output>>
      DBMS_OUTPUT.PUT_LINE ('We are here!'); 
 end;     

     There are several restrictions on the GOTO statement:
      • At least one executable statement must follow a label.
      • The target label must be in the same scope as the GOTO statement.
      • The target label must be in the same part of the PL/SQL block as the GOTO.

    Contrary to popular opinion (including mine), the GOTO statement can come in handy. There are cases where a GOTO statement can simplify the logic in your program. On the other hand, because PL/SQL provides so many different control constructs and modularization techniques, you can almost always find a better way to do something than with a GOTO.
logoblog

Thanks for reading PL/SQL GOTO Statement

Previous
« Prev Post

No comments:

Post a Comment

Please do not enter any spam link in the comment box.