Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to loop through nested table collection from last element to first element

New RootsJun 15 2017 — edited Jun 15 2017

Hi

I have below code . It will print the elements from first to last .  I have to print this element from last element to first element. How can we do this ?

We cannot use last..first methods because it is descending sequence.

DECLARE

type nested_list_type

IS

  TABLE OF NUMBER;

  mylist nested_list_type := nested_list_type();

BEGIN

  mylist.extend(3);

  mylist(1) := 1;

  mylist(2) := 100;

  mylist(3) := 60;

  FOR i IN mylist.first..mylist.last

  LOOP

    IF (mylist.exists(i)) THEN

      dbms_output.put_line(mylist(i));

    END IF;

  END LOOP;

END;

Excepted output :

60

100

1

This post has been answered by Anton Scheffer on Jun 15 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 13 2017
Added on Jun 15 2017
5 comments
1,475 views