Collection Exceptions

The following table provides the collection exceptions(or we can say predefined exceptions) and when they are raised:



Exception Raised whenOracle Error
COLLECTION_IS_NULLYou try to operate on an atomically null collection.ORA-06531
NO_DATA_FOUNDA subscript designates an element that was deletedORA-01403
SUBSCRIPT_BEYOND_COUNTA subscript exceeds the number of elements in a collectionORA-06533
SUBSCRIPT_OUTSIDE_LIMITA subscript is outside the legal rangeORA-06532
VALUE_ERROR A subscript is null or not convertible to an integer ORA-06502

 Raised in program:
DECLARE
TYPE NumList IS TABLE OF NUMBER;
nums NumList;  -- atomically null
BEGIN
/* Assume execution continues despite the raised exceptions. */
   nums(1) := 1;            -- raises COLLECTION_IS_NULL       (1)
   nums := NumList(1,2);  -- initialize table
   nums(NULL) := 3          -- raises VALUE_ERROR              (2)
   nums(0) := 3;            -- raises SUBSCRIPT_OUTSIDE_LIMIT  (3)
   nums(3) := 3;            -- raises SUBSCRIPT_BEYOND_COUNT   (4)
   nums.DELETE(1);  -- delete element 1

   IF nums(1) = 1 THEN ...  -- raises NO_DATA_FOUND            (5)

Example:
declare
  TYPE TYPE_NAME_NUM IS TABLE OF INTEGER;
  nums TYPE_NAME_NUM; /*:=TYPE_NAME_NUM(100,200,300,400)*/;
begin
  null;
  nums(1) := 1;
exception
  when COLLECTION_IS_NULL then
    dbms_output.put_line(sqlerrm);
/*ORA-06531: Reference to uninitialized collection*/
  
end;





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...