Question For Collections

PL/SQL Interview Question  for Collections.

What is Collection? How many type of collection?
Why or when we will use collection?
What is the difference between PL/SQL table, Nested table and Varrays ?
What are common exception related with collection?
What are common methods of handling exceptions?
Give sample defination of varray of object and table of object?
What is the difference between Collection and Record?
What is inline storage and out of line stogare of the nested table?
Write a program using collections.

Difference Between Collection and Record

What is the difference between Collection and Records?



CollectionRecord
The internal components always have the same data type, and are called elementsThe internal components can have different data types, and are called fields
You can access each element of a collection variable by its unique indexYou can access each field of a record variable by its name
Syntax: variable_name(index).Syntax: variable_name.field_name
To create a collection variable : define a collection type and then create a variable of that type or use %TYPE.To create a record variable: define a RECORD type and then create a variable of that type or use %ROWTYPE or %TYPE.
You can create a collection of records.You can create a record that contains collections.

Collection Methods

The following collection methods help generalize code, make collections easier to use, and make your applications easier to maintain:

Method NamePurpose
EXISTS(n)Returns TRUE if the nth element in a collection exists; otherwise returns FALSE.
COUNTReturns the number of elements that a collection currently contains.
LIMITChecks the Maximum Size of a Collection.
FIRSTChecks the Maximum Size of a Collection.
LASTReturns the last (largest) index numbers in a collection that uses integer subscripts.
PRIOR(n)Returns the index number that precedes index n in a collection.
NEXT(n)Returns the index number that succeeds index n.
EXTENDAppends 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.
TRIMRemoves one element from the end of a collection.
TRIM(n)Removes n elements from the end of a collection.
DELETERemoves all elements from a collection, setting COUNT to 0.
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(m,n)                              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(m,n) does nothing.

DBMS_XPLAN

One more way we can see the Explain Plan by using DBMS_XPLAN package. DBMS_XPLAN automatically queries the last plan in PLAN_TABLE. It u...