How to Work With GOTO Statements in PL/SQL

In this article I am going to explain how to work with GOTO statements in PL/SQL.
  • 2995

Introduction

PL/SQL is define as procedure language structure query language.  PL/SQL is developed by oracle. PL/SQL supports many feature like variables, loops, conditions  and exceptions. It also support the concept of array. In present time PL/SQL is integrated component of oracle software. SQL provide limited support for advance programming and PL/SQL fill this gap.

 Block is a basic unit of a PL/SQL application. This block is collection of PL/SQL statements grouped as logical unit. Using  PL/SQL blocks you can create five different type of program units.

  • Stored Function
  • Stored procedure
  • Anonymous Block
  • Trigger
  • Package

GOTO Statement

You can use the potentially dangerous GOTO statement is PL/SQL. GOTO statement transfers control to the labeled statement or block. A GOTO statement in PL/SQL have some restrictions and it can't branch into fallowing statements

  • IF statement
  • CASE statement
  • LOOP statement or sub-block.

Example

DECLARE
x positive := 1;
max_val CONSTANT positive :=10;
BEGIN
dbms_output.enable;
x :=1;
loop
dbms_output.put_line('value of x =' || to_char(x,'999.99'));
x :=x+1;
if x>max_val THEN
goto y;
END IF;
END LOOP;
<<y>>
x:=1;
END;

Output


© 2020 DotNetHeaven. All rights reserved.