Hi.
I need to sort a varray, but i can't create a type.
I found some examples, but they are supressing the repetition , and i need the repetition because i have to do a count,like a group by for example.
(2,7,10,10,7,7,5) and i wil do
2 - 1
7 - 3
10- 2
5 - 1
.
I found this examples.
declare
tab sys.owa_util.vc_arr;
type sorted_tab is table of varchar2(32767) index by binary_integer;
sorted sorted_tab;
id1 pls_integer;
id2 varchar2(32767);
v number :=0;
begin
tab(1) := 2;--'hello';
tab(2) := 5;--'george';
tab(3) := 2;-- 'no';
tab(4) := 7;-- 'no';
tab(5) := 10;-- 'no';
tab(6) := 10;-- 'no';
tab(7) := 2;-- 'no';
tab(8) := 5;-- 'no';
tab(9) := 7;-- 'no';
id1 := tab.first;
while id1 is not null loop
sorted(tab(id1)) := tab(id1);
-- dbms_output.put_line(sorted(tab(id1)) ||' - '|| tab(id1));
id1 := tab.next(id1);
end loop;
id2 := sorted.first;
while id2 is not null loop
dbms_output.put_line(sorted(id2));
id2 := sorted.next(id2);
end loop;
end;
and this..
declare
-- define and initialize a simple Nested Table Collection
type num_tbl is table of number;
l_num_tbl num_tbl:= num_tbl(6,12,9,9,1,54,21, 11, 2);
l_idx integer;
begin
declare
type num_aat_t is table of number index by binary_integer;
l_num_aat num_aat_t;
begin
l_idx:= l_num_tbl.first;
loop
l_num_aat( l_num_tbl(l_idx)):=0;
l_idx:= l_num_tbl.next(l_idx);
exit when l_idx is null;
end loop;
-- remove all elements from l_num_tbl
l_num_tbl.delete;
-- start repopulating l_num_tbl - in the proper order -
-- from the sorted collection of keys in the l_num_aat collection
l_idx:= l_num_aat.first;
loop
l_num_tbl.extend;
l_num_tbl(l_num_tbl.last):= l_idx;
l_idx:= l_num_aat.next(l_idx);
exit when l_idx is null;
end loop;
end;
l_idx:= l_num_tbl.first;
loop
dbms_output.put_line('** '||l_num_tbl(l_idx));
l_idx:= l_num_tbl.next(l_idx);
exit when l_idx is null;
end loop;
end;
thanks by some help...
I will use on oracle 10g and the routine will be in forms 6i