Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: PLSQL Collection
simon wrote:
> I am new to PLSQL.
>
> I declared an index by table:
>
> DECLARE
> TYPE index_by_type IS TABLE OF NUMBER
> INDEX BY BINARY_INTEGER;
> index_by_table index_by_type;
> BEGIN
> index_by_table(12):=...;
> index_by_table(2):=...;
> index_by_table(6):=...;
> index_by_table(8):=...;
> index_by_table.trim(2); /*so, which 2 are trimmed?*/
> END;
>
> Now which elements are trimmed by the .trim() method? The method remove n
> elements from the end of the table. But how elements are sorted and which
> are considered the last n elements? Is it by ascending order of the index
> or by order in which the elements are created?
Why didn't you try it and see?
The first thing you will find is that TRIM is not allowed with INDEX BY.
If you correct for that then the table is no longer sparse, and so you will see this:
SQL> DECLARE
2 TYPE index_by_type IS TABLE OF NUMBER; 3 index_by_table index_by_type := index_by_type(); 4 BEGIN 5 index_by_table.extend(12); 6 index_by_table(12):=12; 7 index_by_table(2):=2; 8 index_by_table(6):=6; 9 index_by_table(8):=8; 10 index_by_table.trim(2); /*so, which 2 are trimmed?*/ 11 for i in 1..12 loop 12 dbms_output.put_line(i || ' - ' || index_by_table(i)); 13 end loop;
1 - 2 - 2 3 - 4 - 5 - 6 - 6 7 - 8 - 8 9 -
![]() |
![]() |