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
heap sort program in pl/sql

Aggregate Assignment The %ROWTYPE declaration cannot include an initialization clause. Though, there are two ways to assign values to all fields in a record at once. At First, t

Example of Using Aggregation on Nested Tables Example: How many students sat each exam WITH C_ER AS (SELECT CourseId, CAST (TABLE (SELECT DISTINCT StudentId, Mark FROM EXAM

Using EXTEND To enlarge the size of a collection, use EXTEND. This process has 3 forms. The EXTEND appends one null element to a collection. And the EXTEND(n) appends n null e

Effects of NULL in Table Literal When a VALUES expression appears as the source value for an SQL INSERT statement, the key word NULL can appear as a field value, such that for

V ariables and Constants in PL/SQL The PL/SQL permits you to declare constants and variables, and then use them in SQL and procedural statements anywhere in the expression. Th

TYPES OF EVOLUTION - Sequential evolution                  :                    Minor changes in the gene pool of a population from one generation to the next, with the resul

Identifiers You use identifiers to name the PL/SQL program items and units that include constants, variables, cursors, exceptions, cursor variables, subprograms, and packages.

Parameter and Keyword Description: cursor_name: This identifies an explicit cursor formerly declared within the present scope. cursor_variable_name: These identif

Need to change mysql query to PDO Project Description: I want someone to convert me 1 .php file that includes some sql/mysql stuff to PDO is a very small file. Skills requ