Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask PL-SQL Expert

Parameter and Keyword Description:

label_name:

This is an undeclared identifier which optionally labels a loop. When used, the label_name should be enclosed by double angle brackets and should appear at the starting of the loop. Optionally, the label_name (not enclosed in the angle brackets) can also appear at the ending of the loop.

You can use the label_name in an EXIT statement to exit the loop labelled by the label_name. You can exit not only the present loop, but any enclosing loop.

You cannot position the index of a FOR loop from the nested FOR loop if both indexes have similar name unless the outer loop is labeled by the label_name and you can use the dot notation, which is as shown below:

label_name.index_name

In the illustration below, you can compare the two loop indexes that have similar name, one used by an enclosing loop, and the other by a nested loop:

<>

FOR ctr IN 1..20 LOOP

...

<>

FOR ctr IN 1..10 LOOP

IF outer.ctr > ctr THEN ...

END LOOP inner;

END LOOP outer;

basic_loop_statement:

The simplest form of the LOOP statement is the fundamental (or unlimited) loop that encloses a series of statements between the keywords LOOP and END LOOP. With each of the iteration of loop, the series of statements is executed, then the control resume at the top of the loop. When further processing is impossible or undesirable, you can use the GOTO, EXIT, or RAISE statement to complete the loop. The raised exception will also complete the loop.

while_loop_statement:

The WHILE-LOOP statement relates a Boolean expression with a series of statements enclosed by the keywords LOOP & END LOOP. Before each of the iteration of the loop, the expression is computed. If the expression results TRUE, the series of the statements is executed, and then control the resumes at the top of the loop. If the expression results FALSE or NULL, the loop is then bypassed and the control passes to the next statement.

boolean_expression:

This is an expression which results the Boolean value TRUE, FALSE, & NULL. It is related with a series of statements that is executed only if the expression results TRUE.

for_loop_statement:

While the number of iterations through a WHILE loop is unfamiliar until the loop complete, the number of iterations during a FOR loop is acknowledged before the loop is entered. The Numeric FOR loops iterate over a specific range of integers. The range is section of an iteration scheme that is enclosed by the keywords FOR and LOOPS.

The range is computed when the FOR loop is primary entered and is never re-evaluated. The series of statements in the loop is executed once for each integer in the range defined by the ower_bound..upper_bound.  Subsequent to the each and every iteration, the loop index is incremented.

index_name:

This is an undeclared identifier which names the loop index. Its scope is the loop itself. And therefore, you cannot reference the index outside the loop.

The implicit declaration of the index_name overrides any other declaration outside the loop. Therefore, another variable with similar name cannot be referenced inside the loop unless a label is used, which is as shown below:

<

>

DECLARE

num NUMBER;

BEGIN

...

FOR num IN 1..10 LOOP

...

IF main.num > 5 THEN -- refers to the variable num,

... -- not to the loop index

END IF;

END LOOP;

END main;

lower_bound .. upper_bound:

These are the expressions which should results integer values. The expressions are computed only when the loop is primary entered. By default, the loop index is assigned the value of the lower_bound. If that value is not bigger than the value of the upper_bound, the series of statements in the loop is executed, and then the index is incremented. If the value of the index is still not bigger than the value of the upper_bound, the series of statements is executed again. This procedure repeats until the value of the index is bigger than the value of the upper_bound. By that point, the loop completes.

REVERSE:

By default, the iteration proceeds upward from the lower bound to the upper bound. Though, if you use the keyword REVERSE, the iteration proceeds downward from the upper bound to the lower bound. An illustration is a shown below:

FOR i IN REVERSE 1..10 LOOP -- i starts at 10, ends at 1

-- statements here execute 10 times

END LOOP;

The loop index is assigned the value of the upper_bound. If that value is not less than the value of the lower_bound, the series of statements in the loop is executed, and then the index is decremented. When the value of the index is still not less than the value of the lower_bound, the series of statements is executed again. This procedure repeats until the value of the index is less than the value of the lower_bound. By that point, the loop completes.

cursor_for_loop_statement:

The cursor FOR loop implicitly declares its loop index as the %ROWTYPE record, opens a cursor, repetitively fetches rows of values from the result set into fields in the record, and closes the cursor when all the rows have been processed. And hence, the series of the statements in the loop is executed once for each row which satisfies the query related with cursor_name.

cursor_name:

This identifies an explicit cursor formerly declared within the present scope. When the cursor FOR loop is entered, the cursor_name cannot refer to a cursor already opened by an OPEN statement or an enclosing cursor FOR loop. 

record_name:

This identifies an implicitly declared record. The record has similar structure as a row retrieved by the cursor_name and is equivalent to the record declared as shown below:

record_name cursor_name%ROWTYPE;

The record is defined only within the loop. You can't refer to its fields outside the loop. The implicit declaration of the record_name overrides any other declaration outside the loop. Therefore, the other record with similar name cannot be referenced inside the loop unless a label is used.

The Fields in the record store column values from the implicitly fetched row. The fields have similar names and datatypes as their equivalent columns. To access the field values, you use the dot notation, which is as shown below:

record_name.field_name:

The Select-items fetched from the FOR loop cursor should have easy names, or if they are expressions, they must have aliases. In the illustration below, wages is an alias for the select item

sal+NVL(comm,0):

CURSOR c1 IS SELECT empno, sal+NVL(comm,0) wages, job ...

cursor_parameter_name:

This identifies the cursor parameter; that is, the variable declared as the formal parameter of the cursor. The cursor parameter can appear in a query where a constant can appear. The formal parameters of the cursor should be IN parameters.

 select_statement:

This is a query related with an internal cursor unavailable to you. Its syntax is such that of the select_into_statement without the INTO clause. The PL/SQL automatically opens, declares, fetches from, and closes the internal cursor. As the select_statement is not an free statement, the implicit SQL cursor does not apply to it. 

PL-SQL, Programming

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

Have any Question?


Related Questions in PL-SQL

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 ...

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 ...

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 ...

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