Use variable.Last to get the last element : Table of number « PL SQL « Oracle PL / SQL






Use variable.Last to get the last element

    

SQL> DECLARE
  2    TYPE charTableType IS TABLE OF NUMBER INDEX BY VARCHAR2(64);
  3    charTable charTableType;
  4    stringTable charTableType;
  5    howmany NUMBER;
  6    which VARCHAR2(64);
  7
  8  BEGIN
  9    charTable('A') := 1;
 10    charTable('B') := 2;
 11    howmany := charTable('A');
 12
 13    stringTable('C') := 3;
 14    stringTable('D') := 1000;
 15    stringTable('D') := 1001;
 16    which := stringTable.FIRST;
 17
 18    dbms_output.put_line(which);
 19    which := stringTable.LAST;
 20    dbms_output.put_line(which);
 21    howmany := stringTable(stringTable.LAST);
 22
 23    dbms_output.put_line(howmany);
 24  END;
 25  /
C
D
1001

PL/SQL procedure successfully completed.

SQL>
SQL>
SQL>
SQL>

   
    
    
    
  








Related examples in the same category

1.use virtual table in PL/SQL block
2.TYPE NumbersTab IS TABLE OF NUMBER.
3.Legal and illegal table assignments.
4.Number Table by BINARY_INTEGER
5.Declare an index-by table variable to hold the employee records that we read in
6.Clear the salaries table by assigning the empty version to it
7.assignments to nested table elements, and the ORA-6533 error.
8.Use nested table constructors.
9.NULL key value in an index-by table
10.Try to insert elements 3 through 5
11.Use the Oracle10g Collection API COUNT method against an element.
12.Use the Oracle10g Collection API DELETE method against a set of elements.
13.Use the Oracle10g Collection API EXISTS method against an element.
14.Use the Oracle10g Collection API EXTEND method against an element.
15.Use the Oracle10g Collection API FIRST and LAST methods against a collection.
16.A nested table of a scalar variable:
17.Associate array: varchar2 to number map
18.Delete a elements from 2, 3 and 4.
19.Delete element 2.
20.number_list.EXTEND(2): Add two null value members at the end of the list.
21.number_list.EXTEND(3,4): Add three members at the end of the list and copy the contents of item 4
22.EXISTS method
23.Extend space in number list.
24.FIRST method returns the lowest subscript value used in a collection
25.Table of number index by varchar2