Use the Oracle10g Collection API FIRST and LAST methods against a collection.
SQL>
SQL> SET ECHO ON
SQL> SET SERVEROUTPUT ON SIZE 1000000
SQL>
SQL> DECLARE
2
3
4 TYPE number_table IS TABLE OF INTEGER INDEX BY VARCHAR2(9 CHAR);
5
6
7 number_list NUMBER_TABLE;
8
9 BEGIN
10
11
12 number_list('One') := 1;
13 number_list('Two') := 2;
14 number_list('Nine') := 9;
15
16
17 DBMS_OUTPUT.PUT_LINE('FIRST Index :'||number_list.FIRST);
18 DBMS_OUTPUT.PUT_LINE('NEXT Index :'||number_list.NEXT(number_list.FIRST));
19
20
21 DBMS_OUTPUT.PUT_LINE(CHR(10)||'LAST Index :'||number_list.LAST);
22 DBMS_OUTPUT.PUT_LINE(' PRIOR Index :'||number_list.PRIOR(number_list.LAST));
23
24 END;
25 /
FIRST Index :Nine
NEXT Index :One
LAST Index :Two
PRIOR Index :One
PL/SQL procedure successfully completed.