Collection methods in pl sql, PL-SQL Programming

Assignment Help:

Collection Methods:

 The collection method is a built-in function or procedure which operates on the collections and is called using the dot notation. The methods like the COUNT, EXISTS, LIMIT, FIRST, LAST, NEXT, EXTEND, PRIOR, TRIM, & DELETE helpful to normalize the code, make collections easier to use, and make your applications easier to sustain.

The COUNT, EXISTS, LIMIT, PRIOR, FIRST, LAST, and NEXT are the functions, that appear as part of an expression. The TRIM, EXTEND, and DELETE are the procedures, that appear as a statement. The EXISTS, NEXT, PRIOR, TRIM, EXTEND, and DELETE take integer parameters.

Syntax:

 

467_collaction function in pl sql.png

Keyword and Parameter Description

collection_name:

These identify an index-by table, varray, or nested table formerly declared within the present scope.

COUNT:

The COUNT returns to the number of elements which a collection presently contains, that is helpful as the present size of a collection is not always known. You can use the COUNT wherever an integer expression is allowed.

For varrays, the COUNT always equals to LAST. For nested tables, generally, COUNT equals to LAST. But, if you delete elements from the middle of the nested table, the COUNT is smaller than LAST.

DELETE:

This procedure has 3 forms. The DELETE eliminates all the elements from a collection. The DELETE (n) eliminates the nth element from a nested table. If n is null, the DELETE (n) does nothing. The DELETE (m,n) eliminates all the elements in the range of m..n from a nested table. If m is bigger than n or if m or n is null, then DELETE (m,n) does nothing.

Index:

This is an expression which should yield an integer.

EXISTS:

The EXISTS(n) returns TRUE when the nth element in a collection exists. Or else, EXISTS(n) returns FALSE. Primarily, you can use EXISTS with DELETE to sustain the sparse nested tables. You can also use the EXISTS to avoid raising an exception whenever you reference a nonexistent element. When passed an out-of-range subscript, the EXISTS returns FALSE rather than of raising the SUBSCRIPT_OUTSIDE_LIMIT.

EXTEND:

This procedure has 3 forms. The EXTEND appends one null element to the collection. The EXTEND(n) appends n null elements to the collection. The EXTEND(n,i) appends n copies of the ith element to the  collection. The EXTEND operates on the internal size of the collection. Therefore, if EXTEND encounters deleted elements, it involves them in its tally.

FIRST, LAST:

The FIRST & LAST return the first & last (lowest limit & upper limit) index numbers in a collection. If the collection is blank, the FIRST and LAST return NULL. When the collections contain only one element, the FIRST and LAST return similar index number. For varrays, the FIRST always returns 1 and the LAST always equals to COUNT. For the nested tables, generally, LAST equals to COUNT. But, when you delete elements from the middle of the nested table, the LAST is larger than COUNT.

LIMIT:

For the nested tables, which have no maximum size, the LIMIT returns NULL. For varrays, the LIMIT returns the maximum number of elements which a varray can contain (that you should specify in its type definition).

NEXT, PRIOR:

The PRIOR(n) returns the index number which precedes an index n in a collection. The NEXT(n) returns the index number which succeed index n. If n has no predecessor, then the PRIOR(n) returns NULL. Similarly, if n has no successor, the NEXT(n) returns the NULL.

TRIM:

This procedure has 2 forms. The TRIM eliminates one element from the end of the collection. The TRIM(n) eliuminates n elements from the end of the  collection. If n is bigger than COUNT, then the TRIM(n) raises the SUBSCRIPT_BEYOND_COUNT. The TRIM operates on the internal size of a collection. Therefore, if TRIM encounters deleted elements, it involves them in its tally.


Related Discussions:- Collection methods in pl sql

Advantages of wrapping, Advantages of Wrapping   The PL/SQL Wrapper co...

Advantages of Wrapping   The PL/SQL Wrapper convert the PL/SQL source code into a transitional form of the object code. By hiding the application internals, the Wrapper secure

Dynamic ranges- iterative control, Dynamic Ranges The PL/SQL lets you det...

Dynamic Ranges The PL/SQL lets you determine the loop range dynamically at run time, as the example below shows: SELECT COUNT(empno) INTO emp_count FROM emp; FOR i IN 1..emp_cou

Table represents an extension - sql, Table Represents an Extension - SQL ...

Table Represents an Extension - SQL It describes how each tuple in a relation represents a true instantiation of some predicate and each true instantiation is represented by s

I need a ppd-cpa or filesharing site, PPD , CPA, Filesharing Site Projec...

PPD , CPA, Filesharing Site Project Description: This is very easy I need a PPD , CPA, Filesharing Site. [PPD] stands for (pay per download) example hotsharecash [Files

Product-specific packages in pl/sql, Product-specific Packages The Ora...

Product-specific Packages The Oracle and different Oracle tools are supplied with the product-specific packages which help you to build the PL/SQL-based applications. For illu

Biconditional - sql, Biconditional - SQL The biconditional p ↔ q can b...

Biconditional - SQL The biconditional p ↔ q can be expressed in Tutorial D by p = q and the same is true of SQL. The question then arises as to whether, in SQL, p = q is equiv

Parameter and keyword description - select into statement, Parameter and Ke...

Parameter and Keyword Description: select_item: This select_item is a value returned by the SELECT statement, and then assigned to the equivalent variable or field in the

How pl/sql resolves the calls? , How Calls Are Resolved? The figure sho...

How Calls Are Resolved? The figure shows that how the PL/SQL compiler resolves the subprogram calls. When the compiler encounters the procedure or function call, it tries to di

Parameter and keyword description - fetch statement, Parameter and Keyword ...

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

Cursors - syntax, Cursors   To execute the multi-row query, the Oracle...

Cursors   To execute the multi-row query, the Oracle opens an unnamed work region which stores the processing information. The cursor names the work region, access the informa

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd