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:


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;


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
Fetching with a Cursor The FETCH statements retrieve the rows in the result set one at a time. After each and every fetch, the cursor advance to the next row in the result set

At times, customers make mistakes in submitting their orders and call to cancel the order. Brewbean’s wants to create a trigger that automatically updates the stock level of all pr

1. Create a procedure called TAX_COST_SP to accomplish the tax calculation task. Keep in mind that the state and subtotal values are inputs into the procedure and the procedure is

FETCH Statement The FETCH statement retrieve rows of data one at a time from the result set of the multi-row query. The data is stored in fields or variables which correspond t

SSRS Report Writing Project Description: This report is part of a larger project to make a SQL Server Reporting Service (SSRS) based reporting solution. There can be more rep

Naming Conventions The similar naming conventions apply to all PL/SQL program items and units including the variables, cursors, constants, cursor variables, procedures, exception

Keyword and Parameter Description: table_reference: This specifies a table or view that should be accessible when you execute the DELETE statement, and for that you must

Quantification in SQL To quantify something, as the theory book has it, is to state its quantity, to say how many of it there are. For example, in Tutorial D the expression CO

Relational Operators and Logical Operators It prepares the ground for subsequent sections in which each specific relational operator is paired with its logical counterpart, su

Object Type: The object type is a user-defined composite datatype which encapsulates a data structure along with the functions and procedures required to manipulate the data