PRIOR v15

The PRIOR method returns the subscript that precedes a specified subscript in a collection. The method takes a single argument: the subscript that you are testing for. The syntax is:

<collection>.PRIOR(<subscript>)

Where collection is the name of the collection.

If the subscript specified doesn't have a predecessor, PRIOR returns NULL. If the specified subscript is greater than the last subscript in the collection, the method returns the last subscript. If you specify a NULL subscript, PRIOR doesn't return a value.

This example returns the subscript that precedes subscript 100 in the associative array sparse_arr:

DECLARE
    TYPE sparse_arr_typ IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
    sparse_arr      sparse_arr_typ;
BEGIN
    sparse_arr(-100)  := -100;
    sparse_arr(-10)   := -10;
    sparse_arr(0)     := 0;
    sparse_arr(10)    := 10;
    sparse_arr(100)   := 100;
    DBMS_OUTPUT.PUT_LINE('PRIOR element: ' || sparse_arr.prior(100));
END;

PRIOR element: 10