<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Sorting PL/SQL Collections, the quite simple way (part two: Have the SQL Engine do the heavy lifting)</title>
	<atom:link href="http://technology.amis.nl/2006/05/31/sorting-plsql-collections-the-quite-simple-way-part-two-have-the-sql-engine-do-the-heavy-lifting/feed/" rel="self" type="application/rss+xml" />
	<link>http://technology.amis.nl/2006/05/31/sorting-plsql-collections-the-quite-simple-way-part-two-have-the-sql-engine-do-the-heavy-lifting/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sorting-plsql-collections-the-quite-simple-way-part-two-have-the-sql-engine-do-the-heavy-lifting</link>
	<description></description>
	<lastBuildDate>Fri, 12 Apr 2013 10:04:09 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
	<item>
		<title>By: Janos Ujvari</title>
		<link>http://technology.amis.nl/2006/05/31/sorting-plsql-collections-the-quite-simple-way-part-two-have-the-sql-engine-do-the-heavy-lifting/#comment-3370</link>
		<dc:creator>Janos Ujvari</dc:creator>
		<pubDate>Fri, 30 Sep 2011 09:32:24 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=1217#comment-3370</guid>
		<description><![CDATA[Great post
thank you very much.]]></description>
		<content:encoded><![CDATA[<p>Great post<br />
thank you very much.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shab</title>
		<link>http://technology.amis.nl/2006/05/31/sorting-plsql-collections-the-quite-simple-way-part-two-have-the-sql-engine-do-the-heavy-lifting/#comment-3369</link>
		<dc:creator>shab</dc:creator>
		<pubDate>Wed, 24 Aug 2011 03:04:12 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=1217#comment-3369</guid>
		<description><![CDATA[Hi Lucas
Great article and examples -thanks.
One issue though, I got his working for my needs on a relatively small dataset but when I tried to scale it up to sort a pl/sql table of around 4 million rows I received the following error:
ORA-22813: operand value exceeds system limits
This error arises on the following statement.
select cast(multiset(select t_pair
 (actual,
 predicted,
 original_index)
 from table(l_tbl)
 order by predicted desc, original_index asc) as t_pairs)
 into l_tbl
 from dual;
I know that you said that you hadn&#039;t tested it with a large data set, I guess i just did.Â Â  Any suggestions on to sorting larger pl/sql tables?
Thanks
shab]]></description>
		<content:encoded><![CDATA[<p>Hi Lucas<br />
Great article and examples -thanks.<br />
One issue though, I got his working for my needs on a relatively small dataset but when I tried to scale it up to sort a pl/sql table of around 4 million rows I received the following error:<br />
ORA-22813: operand value exceeds system limits<br />
This error arises on the following statement.<br />
select cast(multiset(select t_pair<br />
 (actual,<br />
 predicted,<br />
 original_index)<br />
 from table(l_tbl)<br />
 order by predicted desc, original_index asc) as t_pairs)<br />
 into l_tbl<br />
 from dual;<br />
I know that you said that you hadn&#8217;t tested it with a large data set, I guess i just did.Â Â  Any suggestions on to sorting larger pl/sql tables?<br />
Thanks<br />
shab</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Trout</title>
		<link>http://technology.amis.nl/2006/05/31/sorting-plsql-collections-the-quite-simple-way-part-two-have-the-sql-engine-do-the-heavy-lifting/#comment-3368</link>
		<dc:creator>Trout</dc:creator>
		<pubDate>Fri, 14 May 2010 14:24:16 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=1217#comment-3368</guid>
		<description><![CDATA[Combining this with analytical functions is very useful.Â  I am using the technique in a modeling package that uses bulk inserts to speed the processing of large volumes of rows (35 million).Â  By using this method I can get the analytical function results without having to go to the DB a second time for updates after the inital inserts.]]></description>
		<content:encoded><![CDATA[<p>Combining this with analytical functions is very useful.Â  I am using the technique in a modeling package that uses bulk inserts to speed the processing of large volumes of rows (35 million).Â  By using this method I can get the analytical function results without having to go to the DB a second time for updates after the inital inserts.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Trout</title>
		<link>http://technology.amis.nl/2006/05/31/sorting-plsql-collections-the-quite-simple-way-part-two-have-the-sql-engine-do-the-heavy-lifting/#comment-3367</link>
		<dc:creator>Trout</dc:creator>
		<pubDate>Wed, 28 Apr 2010 19:43:12 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=1217#comment-3367</guid>
		<description><![CDATA[Thanks for this.Â  Saved me a fair bit of time.]]></description>
		<content:encoded><![CDATA[<p>Thanks for this.Â  Saved me a fair bit of time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thaha</title>
		<link>http://technology.amis.nl/2006/05/31/sorting-plsql-collections-the-quite-simple-way-part-two-have-the-sql-engine-do-the-heavy-lifting/#comment-3366</link>
		<dc:creator>Thaha</dc:creator>
		<pubDate>Mon, 12 Oct 2009 13:56:41 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=1217#comment-3366</guid>
		<description><![CDATA[Wonderful example.. Thanks a lot ...]]></description>
		<content:encoded><![CDATA[<p>Wonderful example.. Thanks a lot &#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel</title>
		<link>http://technology.amis.nl/2006/05/31/sorting-plsql-collections-the-quite-simple-way-part-two-have-the-sql-engine-do-the-heavy-lifting/#comment-3365</link>
		<dc:creator>Daniel</dc:creator>
		<pubDate>Fri, 24 Oct 2008 18:07:48 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=1217#comment-3365</guid>
		<description><![CDATA[Thanks for your simple collection sorting method.  I have been looking for a way to do this without relying on an index.

It&#039;s so hard to find clear solutions for what should be simple Oracle tasks.  No wonder I usually do things like this on the Java application side.]]></description>
		<content:encoded><![CDATA[<p>Thanks for your simple collection sorting method.  I have been looking for a way to do this without relying on an index.</p>
<p>It&#8217;s so hard to find clear solutions for what should be simple Oracle tasks.  No wonder I usually do things like this on the Java application side.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: M.Bilal</title>
		<link>http://technology.amis.nl/2006/05/31/sorting-plsql-collections-the-quite-simple-way-part-two-have-the-sql-engine-do-the-heavy-lifting/#comment-3364</link>
		<dc:creator>M.Bilal</dc:creator>
		<pubDate>Tue, 27 Feb 2007 14:59:34 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=1217#comment-3364</guid>
		<description><![CDATA[It is really great, and lot of thanks for this article.]]></description>
		<content:encoded><![CDATA[<p>It is really great, and lot of thanks for this article.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Patrick Sinke</title>
		<link>http://technology.amis.nl/2006/05/31/sorting-plsql-collections-the-quite-simple-way-part-two-have-the-sql-engine-do-the-heavy-lifting/#comment-3363</link>
		<dc:creator>Patrick Sinke</dc:creator>
		<pubDate>Sun, 27 Aug 2006 13:27:14 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=1217#comment-3363</guid>
		<description><![CDATA[I also encountered a way to do it without the necessity to create a type outside the package (which is annoying):

DECLARE
   TYPE typ_sorttabIS TABLE OF NUMBER(1) index by VARCHAR2(100) ;
   l_order_tab typ_sorttab;
   ln_pos NUMBER(8) ;
   lv_input VARCHAR2(100) ;
   lv_input_string varchar2(100) ;
   lb_doorgaan boolean default TRUE;
   lv_result VARCHAR2(100) := &#039;;&#039;; -- string begint met een &#039;;&#039;
BEGIN
      lv_input_string := &#039;;BLA;DIE;BLOE;TEST;&#039;
      -- 1e gedeelte leest de inputstring in een array
      ln_pos := instr(lv_input_string, &#039;;&#039;);
      WHILE lb_doorgaan
      LOOP
         lv_input := substr(lv_input_string, 1, ln_pos-1) ; -- alles tot eerstvolgende scheidingsteken
         IF lv_input is not null
         THEN
           -- deze controle is nodig omdat de eerste keer een lege string zal opleveren
           l_order_tab(lv_input) := 1 ;
         END IF;
         lv_input_string := substr(lv_input_string, ln_pos + 1) ; -- input_string min input
         ln_pos := instr(lv_input_string, &#039;;&#039;) ;-- volgende scheidingsteken
         lb_doorgaan := ln_pos &gt; 0 ; -- scheidingstekens nog aanwezig
      END LOOP ;
      -- 2e gedeelte voor output
      lv_input := l_order_tab.first ;
      WHILE lv_input IS NOT NULL
      LOOP
         lv_result := lv_result &#124;&#124; lv_input &#124;&#124; &#039;;&#039; ;
         lv_input := l_order_tab.next(lv_input) ;
      END LOOP ;
      --
end;

 The trick is too create a table of number with index on the field to be sorted. In this example the array is filled manually from a comma-separated string and sorted by looping through the array in order of index.]]></description>
		<content:encoded><![CDATA[<p>I also encountered a way to do it without the necessity to create a type outside the package (which is annoying):</p>
<p>DECLARE<br />
   TYPE typ_sorttabIS TABLE OF NUMBER(1) index by VARCHAR2(100) ;<br />
   l_order_tab typ_sorttab;<br />
   ln_pos NUMBER(8) ;<br />
   lv_input VARCHAR2(100) ;<br />
   lv_input_string varchar2(100) ;<br />
   lb_doorgaan boolean default TRUE;<br />
   lv_result VARCHAR2(100) := &#8216;;&#8217;; &#8212; string begint met een &#8216;;&#8217;<br />
BEGIN<br />
      lv_input_string := &#8216;;BLA;DIE;BLOE;TEST;&#8217;<br />
      &#8212; 1e gedeelte leest de inputstring in een array<br />
      ln_pos := instr(lv_input_string, &#8216;;&#8217;);<br />
      WHILE lb_doorgaan<br />
      LOOP<br />
         lv_input := substr(lv_input_string, 1, ln_pos-1) ; &#8212; alles tot eerstvolgende scheidingsteken<br />
         IF lv_input is not null<br />
         THEN<br />
           &#8212; deze controle is nodig omdat de eerste keer een lege string zal opleveren<br />
           l_order_tab(lv_input) := 1 ;<br />
         END IF;<br />
         lv_input_string := substr(lv_input_string, ln_pos + 1) ; &#8212; input_string min input<br />
         ln_pos := instr(lv_input_string, &#8216;;&#8217;) ;&#8211; volgende scheidingsteken<br />
         lb_doorgaan := ln_pos &gt; 0 ; &#8212; scheidingstekens nog aanwezig<br />
      END LOOP ;<br />
      &#8212; 2e gedeelte voor output<br />
      lv_input := l_order_tab.first ;<br />
      WHILE lv_input IS NOT NULL<br />
      LOOP<br />
         lv_result := lv_result || lv_input || &#8216;;&#8217; ;<br />
         lv_input := l_order_tab.next(lv_input) ;<br />
      END LOOP ;<br />
      &#8211;<br />
end;</p>
<p> The trick is too create a table of number with index on the field to be sorted. In this example the array is filled manually from a comma-separated string and sorted by looping through the array in order of index.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kate Johnson</title>
		<link>http://technology.amis.nl/2006/05/31/sorting-plsql-collections-the-quite-simple-way-part-two-have-the-sql-engine-do-the-heavy-lifting/#comment-3362</link>
		<dc:creator>Kate Johnson</dc:creator>
		<pubDate>Wed, 23 Aug 2006 23:40:52 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=1217#comment-3362</guid>
		<description><![CDATA[Thank you so much for this article, I have been hunting for how to properly use TABLE/CAST and now you made it even easier with TABLE/CAST/MULTISET.  Thank you very much.  2 days of searching is now over.

Next, INSERT/UPDATE/DELETE examples....]]></description>
		<content:encoded><![CDATA[<p>Thank you so much for this article, I have been hunting for how to properly use TABLE/CAST and now you made it even easier with TABLE/CAST/MULTISET.  Thank you very much.  2 days of searching is now over.</p>
<p>Next, INSERT/UPDATE/DELETE examples&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Francois</title>
		<link>http://technology.amis.nl/2006/05/31/sorting-plsql-collections-the-quite-simple-way-part-two-have-the-sql-engine-do-the-heavy-lifting/#comment-3361</link>
		<dc:creator>Francois</dc:creator>
		<pubDate>Wed, 31 May 2006 12:32:43 +0000</pubDate>
		<guid isPermaLink="false">http://technology.amis.nl/blog/?p=1217#comment-3361</guid>
		<description><![CDATA[Great !
Another solution to sort a collection of records by using the . (dot) notation:

create or replace TYPE typ_emp_rec AS OBJECT( empno NUMBER(4), ENAME VARCHAR(10) )
/

create or replace TYPE typ_tab_emp_rec AS TABLE OF typ_emp_rec
/


SQL&gt; declare
  2    tremp   typ_tab_emp_rec := typ_tab_emp_rec( null);
  3    tremp2  typ_tab_emp_rec := typ_tab_emp_rec( null);
  4    nb      pls_integer := 0 ;
  5  begin
  6
  7   tremp.extend(5) ;
  8   for i In reverse 1..5 loop
  9    nb := nb + 1 ;
 10    tremp(nb) :=  new typ_emp_rec(i, &#039;Name&#039; &#124;&#124; to_char(i) ) ;
 11   end loop ;
 12
 13   -- output the collection non-sorted --
 14   dbms_output.put_line( &#039;*** non-sorted collection ***&#039; ) ;
 15   for i In tremp.first .. tremp.last loop
 16      dbms_output.put_line( tremp(i).ename ) ;
 17   end loop ;
 18
 19   select cast ( multiset(   select t.*
 20                             from table( tremp ) t
 21                             order by t.ename
 22                           ) as typ_tab_emp_rec)
 23   into tremp2
 24   from dual;
 25   -- output the collection sorted on ename --
 26   dbms_output.put_line( &#039;*** sorted collection (field 2) ***&#039; ) ;
 27   for i In tremp2.first .. tremp2.last loop
 28      dbms_output.put_line( tremp2(i).ename ) ;
 29   end loop ;
 30  end ;
 31
 32  /
*** non-sorted collection ***
Name5
Name4
Name3
Name2
Name1
*** sorted collection (field 2) ***
Name1
Name2
Name3
Name4
Name5

ProcÃ©dure PL/SQL terminÃ©e avec succÃ¨s.]]></description>
		<content:encoded><![CDATA[<p>Great !<br />
Another solution to sort a collection of records by using the . (dot) notation:</p>
<p>create or replace TYPE typ_emp_rec AS OBJECT( empno NUMBER(4), ENAME VARCHAR(10) )<br />
/</p>
<p>create or replace TYPE typ_tab_emp_rec AS TABLE OF typ_emp_rec<br />
/</p>
<p>SQL&gt; declare<br />
  2    tremp   typ_tab_emp_rec := typ_tab_emp_rec( null);<br />
  3    tremp2  typ_tab_emp_rec := typ_tab_emp_rec( null);<br />
  4    nb      pls_integer := 0 ;<br />
  5  begin<br />
  6<br />
  7   tremp.extend(5) ;<br />
  8   for i In reverse 1..5 loop<br />
  9    nb := nb + 1 ;<br />
 10    tremp(nb) :=  new typ_emp_rec(i, &#8216;Name&#8217; || to_char(i) ) ;<br />
 11   end loop ;<br />
 12<br />
 13   &#8212; output the collection non-sorted &#8211;<br />
 14   dbms_output.put_line( &#8216;*** non-sorted collection ***&#8217; ) ;<br />
 15   for i In tremp.first .. tremp.last loop<br />
 16      dbms_output.put_line( tremp(i).ename ) ;<br />
 17   end loop ;<br />
 18<br />
 19   select cast ( multiset(   select t.*<br />
 20                             from table( tremp ) t<br />
 21                             order by t.ename<br />
 22                           ) as typ_tab_emp_rec)<br />
 23   into tremp2<br />
 24   from dual;<br />
 25   &#8212; output the collection sorted on ename &#8211;<br />
 26   dbms_output.put_line( &#8216;*** sorted collection (field 2) ***&#8217; ) ;<br />
 27   for i In tremp2.first .. tremp2.last loop<br />
 28      dbms_output.put_line( tremp2(i).ename ) ;<br />
 29   end loop ;<br />
 30  end ;<br />
 31<br />
 32  /<br />
*** non-sorted collection ***<br />
Name5<br />
Name4<br />
Name3<br />
Name2<br />
Name1<br />
*** sorted collection (field 2) ***<br />
Name1<br />
Name2<br />
Name3<br />
Name4<br />
Name5</p>
<p>ProcÃ©dure PL/SQL terminÃ©e avec succÃ¨s.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
