Monday 11 May 2015

Collection Methods in PL/SQL

PL/SQL collection method is a built-in function or procedure that operates on collections. The collection method is called using dot(.) notation.

List of methods available in PL/SQL:
1. EXISTS
2. COUNT
3. LIMIT
4. FIRST
5. LAST
6. PRIOR
7. NEXT
8. EXTEND
9. TRIM
10.DELETE

Let us discuss one by one in details
1. EXISTS:
     It is a function which returns TRUE if the nth Element in a collection exists.

2. COUNT:
     It is a function which returns the number of elements a collection currently contains.

3. LIMIT:
    It is a function which returns maximum number of elements that a varray can contain.

4. FIRST:
    It is a function which returns smallest subscript values in a collection.

5. LAST :
    It is a function which returns largest subscript values in a collection.

6. PRIOR:
    It is a function which returns the subscript that precedes index n in a collection.

7. NEXT:
    It is a function which returns the subscript that succeeds index n in a collection.

8. EXTEND:
    It is a procedure and it has 3 forms
    EXTEND: It appends one null element to a collection.
    EXTEND(n): It appends n null elements to a collection.
    EXTEND(n,i): It appends n copies of the ith element to a collection
   You cannot use EXTEND with associative arrays.

9. TRIM :
   It is a procedure and it has 2 forms
   TRIM: It removes one element from the end of a collection
   TRIM(n): It removes n elements from the end of a collection.
   If n is greater than the count then it raised SUBSCRIPT_BEYOND_COUNT exception.
   You cannot use TRIM with index-by tables

10. DELETE:
    It is a procedure and it has 3 forms
    DELETE: It removes all elements from the collection.
    DELETE(n): It removes the nth element from an associative array or nested table.
    DELETE(m,n): It removes all elements in the range m..n from an associative array or  nested table.

No comments: