Hope this helps...Code:SQL> get nested_table_2 1 declare 2 TYPE NumList IS TABLE OF INTEGER; 3 nums NumList := Numlist(12,10,8,8,10,12,7,3,7,7); 4 L_temp int; 5 begin 6 dbms_output.put_line('before sorting '); 7 FOR I in nums.FIRST ..nums.LAST Loop 8 dbms_output.put_line(nums(I)); 9 END loop; 10 --- sort netsted table 11 FOR M in nums.FIRST .. (nums.LAST - 1) LOOP 12 FOR N in (M+1) .. nums.LAST LOOP 13 if nums(M) > nums(N) then 14 -- swap the values 15 L_temp := nums(N); 16 nums(N) := nums(M); 17 nums(M) := L_temp; 18 end if; 19 END LOOP; 20 END LOOP; 21 --- using first and last 22 dbms_output.put_line('after sorting '); 23 FOR I in nums.FIRST ..nums.LAST Loop 24 dbms_output.put_line(nums(I)); 25 END loop; 26 --- delete duplicate 27 FOR M in nums.FIRST .. (nums.LAST -1) Loop 28 if nums(M) >= nums(M+1) then 29 nums(M) := NULL ; 30 end if; 31 END loop; 32 dbms_output.put_line('after deleting duplicates '); 33 FOR I in nums.FIRST ..nums.LAST Loop 34 dbms_output.put_line(nums(I)); 35 END loop; 36* end; 37 / before sorting 12 10 8 8 10 12 7 3 7 7 after sorting 3 7 7 7 8 8 10 10 12 12 after deleting duplicates 3 7 8 10 12 PL/SQL procedure successfully completed.




Reply With Quote