Using first and last - collection method, PL-SQL Programming

Using FIRST and LAST

FIRST and LAST return the first and last (minimum and maximum) index numbers in a collection. When the collection is empty, the FIRST and LAST return NULL. If the collections contains only one element, the FIRST and LAST return the same index number, as the example below shows:

IF courses.FIRST = courses.LAST THEN ... -- only one element

The later example shows that you can use FIRST and LAST to specify the lower and upper bounds of a loop range provided each element in that range exists:

FOR i IN courses.FIRST..courses.LAST LOOP ...

However, you can use the FIRST or LAST where the integer expression is allowed. In the example below, you use FIRST to initialize the loop counter:

i := courses.FIRST;

WHILE i IS NOT NULL LOOP...

For varrays, the FIRST always returns 1 and LAST always equals to COUNT. For the nested tables, FIRST generally returns 1. But, if you delete elements from the beginning of the nested table, FIRST returns a number bigger than 1. Also for the nested tables, the LAST generally equals to COUNT. But, if you delete elements from the middle of a nested table, the LAST becomes larger than COUNT.

Posted Date: 10/4/2012 3:15:27 AM | Location : United States







Related Discussions:- Using first and last - collection method, Assignment Help, Ask Question on Using first and last - collection method, Get Answer, Expert's Help, Using first and last - collection method Discussions

Write discussion on Using first and last - collection method
Your posts are moderated
Related Questions
Great Plains (Microsoft Dynamics) Purchases Report Project Description: I want to build a purchases report that matches the General Ledger. presently, when I join the PM20

Parameter and Keyword Description: record_type_name: This identifies the user-defined type specifier that is used in the subsequent declarations of the records. NOT N

Datatypes Every constant and variable has a datatype that specifies the storage format, constraints, and the valid range of values. The PL/SQL gives a variety of predefined dat

Updating by replacement Syntax: UPDATE ENROLMENT SET Name = 'Ann' WHERE StudentId = SID ('S1'); Note the use of SET, as already noted in connection with direct a

Wrapping and unwrapping in SQL Operators WRAP and UNWRAP in connection with attributes whose declared types are tuple types. Example shows how extension and projection can be

Parameter and Keyword Description: type_name: This identifies a user-defined type specifier that is used in the subsequent declarations of the objects. AUTHID Clause:

Keyword and Parameter Description select_statement: This is a query which returns a result set of the rows. Its syntax is such that of select_ into_statement without the IN

Albeit simple method : These all the truth tables give us our first as albeit simple method for proving a theorem: where check whether it can be written in propositional logic

Declarations in SQL Your program stores values in the variables and constants. As the program executes, the value of the variables can change, but the values constants cannot.

Recursion The Recursion is a powerful method for simplify the design of the algorithms. Principally, the recursion means the self-reference. In the recursive mathematical serie