Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask PL-SQL Expert

GOTO Statement

The GOTO statement branches to a label unconditionally. The label must be exclusive within its scope and should precede an executable statement or a PL/SQL block. If executed, the GOTO statement transfers control to the labeled statement or block. In the following illustration, you go to an executable statement farther down in a series of statements:


BEGIN
...
GOTO insert_row;
...
<>
INSERT INTO emp VALUES...
END;


In the next illustration, you go to a PL/SQL block farther up in a series of statements:


BEGIN
...
<>
BEGIN
UPDATE emp SET ...
...
END;
...
GOTO update_row;
...
END;


The label end_loop in the example below is illegal as it does not precede an executable statement:


DECLARE
done BOOLEAN;
BEGIN
...
FOR i IN 1..50 LOOP
IF done THEN
GOTO end_loop;
END IF;
...

<> -- illegal
END LOOP; -- not an executable statement
END;


To debug the last illustration, now add the NULL statement, as shown:

FOR i IN 1..50 LOOP
IF done THEN
GOTO end_loop;
END IF;
...
<>
NULL; -- an executable statement
END LOOP;


As the following illustration shows, a GOTO statement can branch to an enclosing block from the present block:

DECLARE
my_ename CHAR(10);
BEGIN
<>
SELECT ename INTO my_ename FROM emp WHERE...
BEGIN
...
GOTO get_name; -- branch to enclosing block
END;
END;



Restrictions

Some likely destinations of a GOTO statement are illegal. Particularly, a GOTO statement cannot branch into an IF statement, LOOP statement, or sub-block. For illustration, the following GOTO statement is illegal:



BEGIN
...
GOTO update_row; -- illegal branch into IF statement
...
IF valid THEN
...
<>
UPDATE emp SET...
END IF;
END;

A GOTO statement also cannot branch from one IF statement clause to another, as the following illustration shows:


BEGIN
...
IF valid THEN
...
GOTO update_row; -- illegal branch into ELSE clause
ELSE
...
<>
UPDATE emp SET...
END IF;
END;


The next illustration shows that a GOTO statement cannot branch from an enclose block into a sub-block:


BEGIN
...
IF status = ’OBSOLETE’ THEN
GOTO delete_part; -- illegal branch into sub-block
END IF;
...

BEGIN
...
<>
DELETE FROM parts WHERE...
END;
END;


A GOTO statement also cannot branch out of a subprogram, as the following illustration shows:


DECLARE
...
PROCEDURE compute_bonus (emp_id NUMBER) IS
BEGIN
...
GOTO update_row; -- illegal branch out of subprogram
END;
BEGIN
...
<>
UPDATE emp SET...
END;


Finally, the GOTO statement cannot branch from an exception handler into the present block. For illustration, the following GOTO statement is illegal:


DECLARE
...
pe_ratio REAL;
BEGIN
...
SELECT price / NVL(earnings, 0) INTO pe_ratio FROM ...
<>
INSERT INTO stats VALUES (pe_ratio, ...);
EXCEPTION
WHEN ZERO_DIVIDE THEN
pe_ratio := 0;
GOTO insert_row; -- illegal branch into current block
END;


Though, a GOTO statement can branch from an exception handler into the enclosing block.

PL-SQL, Programming

  • Category:- PL-SQL
  • Reference No.:- M9510136

Have any Question?


Related Questions in PL-SQL

Complete the following tasksin microsoft access create the

Complete the following tasks: In Microsoft Access, create the database and tables that you identified in W3 Assignment 2. In Microsoft Word, write the SQL statements to create the database and tables. Write SQL statement ...

Purpose of the assessment with ulo mapping the purpose of

Purpose of the assessment (with ULO Mapping) The purpose of this assignment is to develop skills in managing data in databases and to gain understanding of data model development and implementation using a commercially a ...

Assignment - queries functions and triggersaimthe aims of

Assignment - Queries, Functions and Triggers Aim The aims of this assignment are to: formulate SQL queries; populate an RDBMS with a real dataset, and analyse the data; design test data for testing SQL queries; create SQ ...

For this assignment you will be provided a database backup

For this assignment, you will be provided a database backup for a database called FinanceDB. You will have to restore this backup to your own version of SQL Server. All of the questions in this assignment relate to the F ...

Continuing the project you have worked on in weeks 1-4 in

Continuing the project you have worked on in Weeks 1-4, in this final week, complete the following tasks: Refine your database and SQL statements by incorporating your instructor's feedback. Verify that the database comp ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As