The following table provides the collection exceptions(or we can say predefined exceptions) and when they are raised:
Raised in program:
Exception | Raised when | Oracle Error |
---|---|---|
COLLECTION_IS_NULL | You try to operate on an atomically null collection. | ORA-06531 |
NO_DATA_FOUND | A subscript designates an element that was deleted | ORA-01403 |
SUBSCRIPT_BEYOND_COUNT | A subscript exceeds the number of elements in a collection | ORA-06533 |
SUBSCRIPT_OUTSIDE_LIMIT | A subscript is outside the legal range | ORA-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: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)
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;
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;