Monday 28 October 2013

Describe Methods related to collections?

A collection method is a built-in function or procedure that operates on collections and is called using dot notation. Collection methods cannot be called from SQL statements. For Varrays, you can suppress only the last element. If the element does not exists, no exception is raised.
collection_name.method_name[(parameters)]

We can use the following methods on a collection:
EXISTS
COUNT
LIMIT
FIRST and LAST
PRIOR and NEXT
EXTEND
TRIM
DELETE

 EXISTS, COUNT, LIMIT, FIRST, LAST, PRIOR, and NEXT are function and EXTEND, TRIM, and DELETE are procedures.

Only the EXISTS method can be used on a NULL collection. All other methods applied on a null collection raise the COLLECTION_IS_NULL error.
EXISTS (index):
Returns TRUE if the index element exists in the collection, else it returns FALSE.
Use this method to be sure you are doing a valid operation on the collection. This method does not raise the SUBSCRIPT_OUTSIDE_LIMIT exception if used on an element that does not exists in the collection.

COUNT:
COUNT returns the number of elements that a collection currently contains. COUNT is useful because the current size of a collection is not always known. For varrays, COUNT always equals LAST. For nested tables, COUNT normally equals LAST. But, if you delete elements from the middle of a nested table, COUNT becomes smaller than LAST.

LIMIT:
For nested tables and associative arrays, which have no maximum size, LIMIT returns NULL. For varrays, LIMIT returns the maximum number of elements that a varray can contain

FIRST and LAST:
Returns the first or last subscript of a collection. If the collection is empty, FIRST and LAST return NULL.

PRIOR (index) and NEXT (index):
Returns the previous or next subscripts of the index element. If the index element has no predecessor, PRIOR (index) returns NULL. Likewise, if index has no successor, NEXT (index) returns NULL.

EXTEND [(n[,i]) :
Used to extend a collection (add new elements).

EXTEND appends one null element to a collection.
EXTEND (n) appends n null elements to a collection.
EXTEND (n,i) appends n copies of the ith element to a collection.

TRIM (n):
Used to decrease the size of a collection.

TRIM removes one element from the end of a collection.
TRIM (n) removes n elements from the end of a collection.

DELETE [(n[,m])] :
Used to delete the element from a collection.

DELETE removes all elements from a collection.
DELETE (n) removes the nth element from an associative array with a numeric key or a nested table. If the associative array has a string key, the element corresponding to the key value is deleted. If n is null, DELETE (n) does nothing.
 DELETE (n,m) removes all elements in the range m..n from an associative array or nested table. If m is larger than n or if m or n is null, DELETE (n,m) does nothing

No comments:

Post a Comment