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!

Sorting (order by) in PL/SQL Collection

User_3ZQRHJul 24 2018 — edited Jul 25 2018

I am working in Oracle 11gR2 running on Linux RHEL machine

I have created a procedure which uses a collection as input parameter.

create or replace TYPE rec AS

OBJECT  (

  id        NUMBER(6),         

  prcs_d         DATE,

  code     VARCHAR2(3 CHAR)     

);

create or replace TYPE tab AS TABLE OF rec;

PROCEDURE upd_table (i_tab in out nocopy tab)

    IS

v_count := i_tab.count;

for i IN 1 ..v_count

        loop

dbms_output.put_line (i_tab(i).id);

end loop;

end;

How can create or have the collection  i_tab sorted/ordered by on the column id in my procedure so that the ids which gets printed are in a ascending or descending order ?

Can i create another collection "locally" where I have the records sorted on the basis of id column after we receive that i_tab collection as input parameter  and then parse through the records one by one inside the loop ?

This post has been answered by Paulzip on Jul 24 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 22 2018
Added on Jul 24 2018
5 comments
3,360 views