<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: The New Order Oracle Coding Challenge 2</title>
	<atom:link href="http://hoopercharles.wordpress.com/2011/08/02/the-new-order-oracle-coding-challenge-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://hoopercharles.wordpress.com/2011/08/02/the-new-order-oracle-coding-challenge-2/</link>
	<description>Miscellaneous Random Oracle Topics: Stop, Think, ... Understand</description>
	<lastBuildDate>Mon, 13 May 2013 14:10:06 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://hoopercharles.wordpress.com/2011/08/02/the-new-order-oracle-coding-challenge-2/#comment-3749</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Thu, 04 Aug 2011 18:56:01 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5232#comment-3749</guid>
		<description><![CDATA[Mohamed,

Good idea to try a pipelined function.  I have not worked with those very much.

As an experiment, I quickly put together an Excel macro/Visual Basic 6 program that accepts a number as input and outputs to the debug window all combinations of the digits in that number:
&lt;pre&gt;
Private Function Combinations(lngNumber As Long) As Long
    Dim i As Integer
    Dim intFlag As Integer
    Dim intDigits As Integer
    Dim intDigit(20) As Integer
    Dim intDigitIndex(20) As Integer
    Dim intAdjustmentPosition As Integer

    intDigits = Len(CStr(lngNumber))
    intAdjustmentPosition = intDigits
    For i = 1 To intDigits
        intDigitIndex(i) = i
    Next i
    
    Do While intAdjustmentPosition &gt; 0
        intFlag = 0
        For i = 1 To intAdjustmentPosition - 1
            If intDigitIndex(i) = intDigitIndex(intAdjustmentPosition) Then
                &#039;Found a duplicate index position in the other values to the left
                intFlag = 1
            End If
        Next i
        If intFlag = 1 Then
            &#039;Try the next index position in this element
            intDigitIndex(intAdjustmentPosition) = intDigitIndex(intAdjustmentPosition) + 1
        Else
            If intAdjustmentPosition = intDigits Then
                &#039;Output
                For i = 1 To intDigits
                    Debug.Print intDigitIndex(i);
                Next i
                Debug.Print &quot;&quot;
                intDigitIndex(intAdjustmentPosition) = 1
                intAdjustmentPosition = intAdjustmentPosition - 1
                intDigitIndex(intAdjustmentPosition) = intDigitIndex(intAdjustmentPosition) + 1
            Else
                &#039;No duplicate so prepare to check the next position
                intAdjustmentPosition = intAdjustmentPosition + 1
            End If
        End If
        
        Do While (intAdjustmentPosition &gt; 0) And (intDigitIndex(intAdjustmentPosition) &gt; intDigits)
            &#039;Roll back one index position as many times as necessary
            intDigitIndex(intAdjustmentPosition) = 1
            intAdjustmentPosition = intAdjustmentPosition - 1
            intDigitIndex(intAdjustmentPosition) = intDigitIndex(intAdjustmentPosition) + 1
        Loop
    Loop
End Function
&lt;/pre&gt;

Now let&#039;s convert that VB 6 code into a function that will eventually return pipelined rows (is SYS.AQ$_MIDARRAY the correct type, I borrowed it from another example posted by someone to this blog - it appears that we *could* use this to return VARCHAR strings:
&lt;pre&gt;
CREATE OR REPLACE FUNCTION COMBINATIONS(SNUMBER IN NUMBER) RETURN SYS.AQ$_MIDARRAY PIPELINED
AS
  TYPE MY_ARRAY IS TABLE OF NUMBER INDEX BY PLS_INTEGER;
  intDigit MY_ARRAY;
  intDigitIndex MY_ARRAY;
  intDigits NUMBER;
  intAdjustmentPosition NUMBER;
  intFlag NUMBER;
  strOutput VARCHAR2(100);
BEGIN
  intDigits := LENGTH(TO_CHAR(SNUMBER));
  intAdjustmentPosition := intDIGITS;
  FOR I IN 1 .. intDigits LOOP
    intDigitIndex(I) := I;
  END LOOP;

  WHILE intAdjustmentPosition &gt; 0 LOOP
    intFlag := 0;
    FOR I IN 1 .. intAdjustmentPosition - 1 LOOP
      IF intDigitIndex(I) = intDigitIndex(intAdjustmentPosition) Then
        -- Found a duplicate index position in the other values to the left
        intFlag := 1;
      END IF;
    END LOOP;
    IF intFlag = 1 Then
      -- Try the next index position in this element
      intDigitIndex(intAdjustmentPosition) := intDigitIndex(intAdjustmentPosition) + 1;
    ELSE
      IF intAdjustmentPosition = intDigits Then
        -- Output
        strOutput := &#039;&#039;;
        FOR i IN 1 .. intDigits LOOP
          strOutput := strOutput &#124;&#124; SUBSTR(TO_CHAR(SNUMBER),intDigitIndex(i),1);
        END LOOP;
 
        DBMS_OUTPUT.PUT_LINE(strOutput);
        intDigitIndex(intAdjustmentPosition) := 1;
        intAdjustmentPosition := intAdjustmentPosition - 1;
        intDigitIndex(intAdjustmentPosition) := intDigitIndex(intAdjustmentPosition) + 1;
      ELSE
        -- No duplicate so prepare to check the next position
        intAdjustmentPosition := intAdjustmentPosition + 1;
      END IF;
    END IF;
        
    WHILE (intAdjustmentPosition &gt; 0) And (intDigitIndex(intAdjustmentPosition) &gt; intDigits) LOOP
      -- Roll back one index position as many times as necessary
      intDigitIndex(intAdjustmentPosition) := 1;
      intAdjustmentPosition := intAdjustmentPosition - 1;
      intDigitIndex(intAdjustmentPosition) := intDigitIndex(intAdjustmentPosition) + 1;
    END LOOP;
  END LOOP;
END;
/
&lt;/pre&gt;
 
&lt;pre&gt;
SET SERVEROUTPUT ON
 
SELECT * FROM TABLE(COMBINATIONS(1234));
 
no rows selected
 
1234
1243
1324
1342
1423
1432
2134
2143
2314
2341
2413
2431
3124
3142
3214
3241
3412
3421
4123
4132
4213
4231
4312
4321
&lt;/pre&gt;

As can be seen by the above output, if we input the 4 digit number 1234, the function outputs all combinations of the digits 1234.  It will work with numbers with 1, 2, 3, 4, 5, 6, 7, 8, 9, and etc. digits.  Let&#039;s fix the function so that it returns pipelined rows:
&lt;pre&gt;
CREATE OR REPLACE FUNCTION COMBINATIONS(SNUMBER IN NUMBER) RETURN SYS.AQ$_MIDARRAY PIPELINED
AS
  TYPE MY_ARRAY IS TABLE OF NUMBER INDEX BY PLS_INTEGER;
  intDigit MY_ARRAY;
  intDigitIndex MY_ARRAY;
  intDigits NUMBER;
  intAdjustmentPosition NUMBER;
  intFlag NUMBER;
  strOutput VARCHAR2(100);
BEGIN
  intDigits := LENGTH(TO_CHAR(SNUMBER));
  intAdjustmentPosition := intDIGITS;
  FOR I IN 1 .. intDigits LOOP
    intDigitIndex(I) := I;
  END LOOP;

  WHILE intAdjustmentPosition &gt; 0 LOOP
    intFlag := 0;
    FOR I IN 1 .. intAdjustmentPosition - 1 LOOP
      IF intDigitIndex(I) = intDigitIndex(intAdjustmentPosition) Then
        -- Found a duplicate index position in the other values to the left
        intFlag := 1;
      END IF;
    END LOOP;
    IF intFlag = 1 Then
      -- Try the next index position in this element
      intDigitIndex(intAdjustmentPosition) := intDigitIndex(intAdjustmentPosition) + 1;
    ELSE
      IF intAdjustmentPosition = intDigits Then
        -- Output
        strOutput := &#039;&#039;;
        FOR i IN 1 .. intDigits LOOP
          strOutput := strOutput &#124;&#124; SUBSTR(TO_CHAR(SNUMBER),intDigitIndex(i),1);
        END LOOP;
 
        PIPE ROW (strOutput);
        intDigitIndex(intAdjustmentPosition) := 1;
        intAdjustmentPosition := intAdjustmentPosition - 1;
        intDigitIndex(intAdjustmentPosition) := intDigitIndex(intAdjustmentPosition) + 1;
      ELSE
        -- No duplicate so prepare to check the next position
        intAdjustmentPosition := intAdjustmentPosition + 1;
      END IF;
    END IF;
        
    WHILE (intAdjustmentPosition &gt; 0) And (intDigitIndex(intAdjustmentPosition) &gt; intDigits) LOOP
      -- Roll back one index position as many times as necessary
      intDigitIndex(intAdjustmentPosition) := 1;
      intAdjustmentPosition := intAdjustmentPosition - 1;
      intDigitIndex(intAdjustmentPosition) := intDigitIndex(intAdjustmentPosition) + 1;
    END LOOP;
  END LOOP;
END;
/
&lt;/pre&gt;
 
&lt;pre&gt;
SELECT * FROM TABLE(COMBINATIONS(1234));
 
COLUMN_VALUE
-----------------
1234
1243
1324
1342
1423
1432
2134
2143
2314
2341
2413
2431
3124
3142
3214
3241
3412
3421
4123
4132
4213
4231
4312
4321

24 rows selected.
&lt;/pre&gt;

Now the interesting thing is that if we input 1234, we are able to use the first, second, third, and fourth characters in the returned values to determine how to reorganize the digits in the original numbers that are supplied by the CONNECT BY syntax:
&lt;pre&gt;
SELECT DISTINCT
  N,
  D
FROM
  (SELECT
    N.N,
    TO_NUMBER(SUBSTR(TO_CHAR(N.N), SUBSTR(P.COLUMN_VALUE,1,1),1) &#124;&#124;
              SUBSTR(TO_CHAR(N.N), SUBSTR(P.COLUMN_VALUE,2,1),1) &#124;&#124;
              SUBSTR(TO_CHAR(N.N), SUBSTR(P.COLUMN_VALUE,3,1),1) &#124;&#124;
              SUBSTR(TO_CHAR(N.N), SUBSTR(P.COLUMN_VALUE,4,1),1)) D
  FROM
    (SELECT
      *
    FROM
      TABLE(COMBINATIONS(1234))) P,
    (SELECT
      ROWNUM+1000 N
    FROM
      DUAL
    CONNECT BY
      LEVEL&lt;=8999) N
  WHERE
    N/10 &lt;&gt; TRUNC(N/10))
WHERE
  N&gt;D
  AND N/D = TRUNC(N/D)
ORDER BY
  N;
&lt;/pre&gt;

I am not sure if the above helps - maybe someone can figure out how to directly feed the numbers from the N inline view into the COMBINATIONS function.]]></description>
		<content:encoded><![CDATA[<p>Mohamed,</p>
<p>Good idea to try a pipelined function.  I have not worked with those very much.</p>
<p>As an experiment, I quickly put together an Excel macro/Visual Basic 6 program that accepts a number as input and outputs to the debug window all combinations of the digits in that number:</p>
<pre>
Private Function Combinations(lngNumber As Long) As Long
    Dim i As Integer
    Dim intFlag As Integer
    Dim intDigits As Integer
    Dim intDigit(20) As Integer
    Dim intDigitIndex(20) As Integer
    Dim intAdjustmentPosition As Integer

    intDigits = Len(CStr(lngNumber))
    intAdjustmentPosition = intDigits
    For i = 1 To intDigits
        intDigitIndex(i) = i
    Next i
    
    Do While intAdjustmentPosition &gt; 0
        intFlag = 0
        For i = 1 To intAdjustmentPosition - 1
            If intDigitIndex(i) = intDigitIndex(intAdjustmentPosition) Then
                'Found a duplicate index position in the other values to the left
                intFlag = 1
            End If
        Next i
        If intFlag = 1 Then
            'Try the next index position in this element
            intDigitIndex(intAdjustmentPosition) = intDigitIndex(intAdjustmentPosition) + 1
        Else
            If intAdjustmentPosition = intDigits Then
                'Output
                For i = 1 To intDigits
                    Debug.Print intDigitIndex(i);
                Next i
                Debug.Print ""
                intDigitIndex(intAdjustmentPosition) = 1
                intAdjustmentPosition = intAdjustmentPosition - 1
                intDigitIndex(intAdjustmentPosition) = intDigitIndex(intAdjustmentPosition) + 1
            Else
                'No duplicate so prepare to check the next position
                intAdjustmentPosition = intAdjustmentPosition + 1
            End If
        End If
        
        Do While (intAdjustmentPosition &gt; 0) And (intDigitIndex(intAdjustmentPosition) &gt; intDigits)
            'Roll back one index position as many times as necessary
            intDigitIndex(intAdjustmentPosition) = 1
            intAdjustmentPosition = intAdjustmentPosition - 1
            intDigitIndex(intAdjustmentPosition) = intDigitIndex(intAdjustmentPosition) + 1
        Loop
    Loop
End Function
</pre>
<p>Now let&#8217;s convert that VB 6 code into a function that will eventually return pipelined rows (is SYS.AQ$_MIDARRAY the correct type, I borrowed it from another example posted by someone to this blog &#8211; it appears that we *could* use this to return VARCHAR strings:</p>
<pre>
CREATE OR REPLACE FUNCTION COMBINATIONS(SNUMBER IN NUMBER) RETURN SYS.AQ$_MIDARRAY PIPELINED
AS
  TYPE MY_ARRAY IS TABLE OF NUMBER INDEX BY PLS_INTEGER;
  intDigit MY_ARRAY;
  intDigitIndex MY_ARRAY;
  intDigits NUMBER;
  intAdjustmentPosition NUMBER;
  intFlag NUMBER;
  strOutput VARCHAR2(100);
BEGIN
  intDigits := LENGTH(TO_CHAR(SNUMBER));
  intAdjustmentPosition := intDIGITS;
  FOR I IN 1 .. intDigits LOOP
    intDigitIndex(I) := I;
  END LOOP;

  WHILE intAdjustmentPosition &gt; 0 LOOP
    intFlag := 0;
    FOR I IN 1 .. intAdjustmentPosition - 1 LOOP
      IF intDigitIndex(I) = intDigitIndex(intAdjustmentPosition) Then
        -- Found a duplicate index position in the other values to the left
        intFlag := 1;
      END IF;
    END LOOP;
    IF intFlag = 1 Then
      -- Try the next index position in this element
      intDigitIndex(intAdjustmentPosition) := intDigitIndex(intAdjustmentPosition) + 1;
    ELSE
      IF intAdjustmentPosition = intDigits Then
        -- Output
        strOutput := '';
        FOR i IN 1 .. intDigits LOOP
          strOutput := strOutput || SUBSTR(TO_CHAR(SNUMBER),intDigitIndex(i),1);
        END LOOP;
 
        DBMS_OUTPUT.PUT_LINE(strOutput);
        intDigitIndex(intAdjustmentPosition) := 1;
        intAdjustmentPosition := intAdjustmentPosition - 1;
        intDigitIndex(intAdjustmentPosition) := intDigitIndex(intAdjustmentPosition) + 1;
      ELSE
        -- No duplicate so prepare to check the next position
        intAdjustmentPosition := intAdjustmentPosition + 1;
      END IF;
    END IF;
        
    WHILE (intAdjustmentPosition &gt; 0) And (intDigitIndex(intAdjustmentPosition) &gt; intDigits) LOOP
      -- Roll back one index position as many times as necessary
      intDigitIndex(intAdjustmentPosition) := 1;
      intAdjustmentPosition := intAdjustmentPosition - 1;
      intDigitIndex(intAdjustmentPosition) := intDigitIndex(intAdjustmentPosition) + 1;
    END LOOP;
  END LOOP;
END;
/
</pre>
<pre>
SET SERVEROUTPUT ON
 
SELECT * FROM TABLE(COMBINATIONS(1234));
 
no rows selected
 
1234
1243
1324
1342
1423
1432
2134
2143
2314
2341
2413
2431
3124
3142
3214
3241
3412
3421
4123
4132
4213
4231
4312
4321
</pre>
<p>As can be seen by the above output, if we input the 4 digit number 1234, the function outputs all combinations of the digits 1234.  It will work with numbers with 1, 2, 3, 4, 5, 6, 7, 8, 9, and etc. digits.  Let&#8217;s fix the function so that it returns pipelined rows:</p>
<pre>
CREATE OR REPLACE FUNCTION COMBINATIONS(SNUMBER IN NUMBER) RETURN SYS.AQ$_MIDARRAY PIPELINED
AS
  TYPE MY_ARRAY IS TABLE OF NUMBER INDEX BY PLS_INTEGER;
  intDigit MY_ARRAY;
  intDigitIndex MY_ARRAY;
  intDigits NUMBER;
  intAdjustmentPosition NUMBER;
  intFlag NUMBER;
  strOutput VARCHAR2(100);
BEGIN
  intDigits := LENGTH(TO_CHAR(SNUMBER));
  intAdjustmentPosition := intDIGITS;
  FOR I IN 1 .. intDigits LOOP
    intDigitIndex(I) := I;
  END LOOP;

  WHILE intAdjustmentPosition &gt; 0 LOOP
    intFlag := 0;
    FOR I IN 1 .. intAdjustmentPosition - 1 LOOP
      IF intDigitIndex(I) = intDigitIndex(intAdjustmentPosition) Then
        -- Found a duplicate index position in the other values to the left
        intFlag := 1;
      END IF;
    END LOOP;
    IF intFlag = 1 Then
      -- Try the next index position in this element
      intDigitIndex(intAdjustmentPosition) := intDigitIndex(intAdjustmentPosition) + 1;
    ELSE
      IF intAdjustmentPosition = intDigits Then
        -- Output
        strOutput := '';
        FOR i IN 1 .. intDigits LOOP
          strOutput := strOutput || SUBSTR(TO_CHAR(SNUMBER),intDigitIndex(i),1);
        END LOOP;
 
        PIPE ROW (strOutput);
        intDigitIndex(intAdjustmentPosition) := 1;
        intAdjustmentPosition := intAdjustmentPosition - 1;
        intDigitIndex(intAdjustmentPosition) := intDigitIndex(intAdjustmentPosition) + 1;
      ELSE
        -- No duplicate so prepare to check the next position
        intAdjustmentPosition := intAdjustmentPosition + 1;
      END IF;
    END IF;
        
    WHILE (intAdjustmentPosition &gt; 0) And (intDigitIndex(intAdjustmentPosition) &gt; intDigits) LOOP
      -- Roll back one index position as many times as necessary
      intDigitIndex(intAdjustmentPosition) := 1;
      intAdjustmentPosition := intAdjustmentPosition - 1;
      intDigitIndex(intAdjustmentPosition) := intDigitIndex(intAdjustmentPosition) + 1;
    END LOOP;
  END LOOP;
END;
/
</pre>
<pre>
SELECT * FROM TABLE(COMBINATIONS(1234));
 
COLUMN_VALUE
-----------------
1234
1243
1324
1342
1423
1432
2134
2143
2314
2341
2413
2431
3124
3142
3214
3241
3412
3421
4123
4132
4213
4231
4312
4321

24 rows selected.
</pre>
<p>Now the interesting thing is that if we input 1234, we are able to use the first, second, third, and fourth characters in the returned values to determine how to reorganize the digits in the original numbers that are supplied by the CONNECT BY syntax:</p>
<pre>
SELECT DISTINCT
  N,
  D
FROM
  (SELECT
    N.N,
    TO_NUMBER(SUBSTR(TO_CHAR(N.N), SUBSTR(P.COLUMN_VALUE,1,1),1) ||
              SUBSTR(TO_CHAR(N.N), SUBSTR(P.COLUMN_VALUE,2,1),1) ||
              SUBSTR(TO_CHAR(N.N), SUBSTR(P.COLUMN_VALUE,3,1),1) ||
              SUBSTR(TO_CHAR(N.N), SUBSTR(P.COLUMN_VALUE,4,1),1)) D
  FROM
    (SELECT
      *
    FROM
      TABLE(COMBINATIONS(1234))) P,
    (SELECT
      ROWNUM+1000 N
    FROM
      DUAL
    CONNECT BY
      LEVEL&lt;=8999) N
  WHERE
    N/10 &lt;&gt; TRUNC(N/10))
WHERE
  N&gt;D
  AND N/D = TRUNC(N/D)
ORDER BY
  N;
</pre>
<p>I am not sure if the above helps &#8211; maybe someone can figure out how to directly feed the numbers from the N inline view into the COMBINATIONS function.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Houri Mohamed</title>
		<link>http://hoopercharles.wordpress.com/2011/08/02/the-new-order-oracle-coding-challenge-2/#comment-3748</link>
		<dc:creator><![CDATA[Houri Mohamed]]></dc:creator>
		<pubDate>Thu, 04 Aug 2011 14:56:50 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5232#comment-3748</guid>
		<description><![CDATA[I didn&#039;t succeed right now to have a pure SQL solution. I have however created a pipelined function giving me the four digit combinations as follows

[sourcecode language=&quot;sql&quot;]

mhouri.world &gt;select * from table(f_get_number(8712));

COLUMN_VALUE                                                                                                            
------------                                                                                                            
        8712                                                                                                            
        8721                                                                                                            
        8172                                                                                                            
        8127                                                                                                            
        8271                                                                                                            
        8217                                                                                                            
        7812                                                                                                            
        7821                                                                                                            
        7182                                                                                                            
        7128                                                                                                            
        7281                                                                                                                                                                                                             
        7218                                                                                                            
        1872                                                                                                            
        1827                                                                                                            
        1782                                                                                                            
        1728                                                                                                            
        1287                                                                                                            
        1278                                                                                                            
        2871                                                                                                            
        2817                                                                                                            
        2781                                                                                                            
        2718                                                                                                                                                                                                                     
        2187                                                                                                            
        2178                                                                                                            

24 rows selected.

mhouri.world &gt;select * from table(f_get_number(7141));

COLUMN_VALUE                                                                                                            
------------                                                                                                            
        7141                                                                                                            
        7114                                                                                                            
        7411                                                                                                            
        7411                                                                                                            
        7114                                                                                                            
        7141                                                                                                            
        1741                                                                                                            
        1714                                                                                                            
        1471                                                                                                            
        1417                                                                                                            
        1174                                                                                                                                                                                                                     
        1147                                                                                                            
        4711                                                                                                            
        4711                                                                                                            
        4171                                                                                                            
        4117                                                                                                            
        4171                                                                                                            
        4117                                                                                                            
        1714                                                                                                            
        1741                                                                                                            
        1174                                                                                                            
        1147                                                                                                                                                                                                                    
        1471                                                                                                            
        1417                                                                                                            

24 rows selected.
[/sourcecode]

and have started figuring out how to use this function with the original numbers selected as follows

[sourcecode language=&quot;sql&quot;]

mhouri.world &gt; SELECT original
  2    FROM
  3      ( select rownum original
  4       from dual connect by level &lt;= 9999
  5       )
  6    WHERE original           &gt;= 1000
  7    AND SUBSTR(original,4,1) != 0
  8  ;

  ORIGINAL                                                                                                              
----------                                                                                                              
      1001                                                                                                              
      1002                                                                                                              
      1003                                                                                                              
      1004                                                                                                              
      1005                                                                                                              
      1006                                                                                                              
      1007                                                                                                              
      1008                                                                                                              
      1009                                                                                                              
      1011                                                                                                              
      1012                                                                                                                                                                                                                         
      1013                                                                                                              
      1014                                                                                                              
      1015                                                                                                              
      1016                                                                                                              
      1017                                                                                                              
      1018                                                                                                              
      1019                                                                                                              
      1021                                                                                                              
      1022                                                                                                              
      1023                                                                                                              
      1024                                                                                                              
    ....                                            
[/sourcecode]

I Still have not found the solution]]></description>
		<content:encoded><![CDATA[<p>I didn&#8217;t succeed right now to have a pure SQL solution. I have however created a pipelined function giving me the four digit combinations as follows</p>
<pre class="brush: sql; title: ; notranslate">

mhouri.world &gt;select * from table(f_get_number(8712));

COLUMN_VALUE                                                                                                            
------------                                                                                                            
        8712                                                                                                            
        8721                                                                                                            
        8172                                                                                                            
        8127                                                                                                            
        8271                                                                                                            
        8217                                                                                                            
        7812                                                                                                            
        7821                                                                                                            
        7182                                                                                                            
        7128                                                                                                            
        7281                                                                                                                                                                                                             
        7218                                                                                                            
        1872                                                                                                            
        1827                                                                                                            
        1782                                                                                                            
        1728                                                                                                            
        1287                                                                                                            
        1278                                                                                                            
        2871                                                                                                            
        2817                                                                                                            
        2781                                                                                                            
        2718                                                                                                                                                                                                                     
        2187                                                                                                            
        2178                                                                                                            

24 rows selected.

mhouri.world &gt;select * from table(f_get_number(7141));

COLUMN_VALUE                                                                                                            
------------                                                                                                            
        7141                                                                                                            
        7114                                                                                                            
        7411                                                                                                            
        7411                                                                                                            
        7114                                                                                                            
        7141                                                                                                            
        1741                                                                                                            
        1714                                                                                                            
        1471                                                                                                            
        1417                                                                                                            
        1174                                                                                                                                                                                                                     
        1147                                                                                                            
        4711                                                                                                            
        4711                                                                                                            
        4171                                                                                                            
        4117                                                                                                            
        4171                                                                                                            
        4117                                                                                                            
        1714                                                                                                            
        1741                                                                                                            
        1174                                                                                                            
        1147                                                                                                                                                                                                                    
        1471                                                                                                            
        1417                                                                                                            

24 rows selected.
</pre>
<p>and have started figuring out how to use this function with the original numbers selected as follows</p>
<pre class="brush: sql; title: ; notranslate">

mhouri.world &gt; SELECT original
  2    FROM
  3      ( select rownum original
  4       from dual connect by level &lt;= 9999
  5       )
  6    WHERE original           &gt;= 1000
  7    AND SUBSTR(original,4,1) != 0
  8  ;

  ORIGINAL                                                                                                              
----------                                                                                                              
      1001                                                                                                              
      1002                                                                                                              
      1003                                                                                                              
      1004                                                                                                              
      1005                                                                                                              
      1006                                                                                                              
      1007                                                                                                              
      1008                                                                                                              
      1009                                                                                                              
      1011                                                                                                              
      1012                                                                                                                                                                                                                         
      1013                                                                                                              
      1014                                                                                                              
      1015                                                                                                              
      1016                                                                                                              
      1017                                                                                                              
      1018                                                                                                              
      1019                                                                                                              
      1021                                                                                                              
      1022                                                                                                              
      1023                                                                                                              
      1024                                                                                                              
    ....                                            
</pre>
<p>I Still have not found the solution</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: utecistu</title>
		<link>http://hoopercharles.wordpress.com/2011/08/02/the-new-order-oracle-coding-challenge-2/#comment-3747</link>
		<dc:creator><![CDATA[utecistu]]></dc:creator>
		<pubDate>Thu, 04 Aug 2011 13:44:49 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5232#comment-3747</guid>
		<description><![CDATA[what about a very short one? (disregard the timing :) )  :
[code]
with nr as 
    (select level+1000 n1,level n2  from dual connect by level&lt;9000)
select a.n1 original,b.n2 combination 
from nr a, nr b 
where   mod(a.n1,b.n2)=0 and a.n1&gt;b.n2 and mod(a.n1,10)&gt;0 and
        cast(multiset(select substr(a.n1,level,1) from dual connect by level&lt;5) as KU$_OBJNUMSET)= 
        cast(multiset(select substr(lpad(b.n2,4,0),level,1) from dual connect by level&lt;5) as KU$_OBJNUMSET)
[/code]]]></description>
		<content:encoded><![CDATA[<p>what about a very short one? (disregard the timing <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  )  :</p>
<pre class="brush: plain; title: ; notranslate">
with nr as 
    (select level+1000 n1,level n2  from dual connect by level&lt;9000)
select a.n1 original,b.n2 combination 
from nr a, nr b 
where   mod(a.n1,b.n2)=0 and a.n1&gt;b.n2 and mod(a.n1,10)&gt;0 and
        cast(multiset(select substr(a.n1,level,1) from dual connect by level&lt;5) as KU$_OBJNUMSET)= 
        cast(multiset(select substr(lpad(b.n2,4,0),level,1) from dual connect by level&lt;5) as KU$_OBJNUMSET)
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://hoopercharles.wordpress.com/2011/08/02/the-new-order-oracle-coding-challenge-2/#comment-3746</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Wed, 03 Aug 2011 22:09:38 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5232#comment-3746</guid>
		<description><![CDATA[There have been a couple of possible solutions posted so far, and there has been no more suggestions posted in the last 36 hours, so I thought that I would share the solution that I developed.

First, we need to find a way to build all 24 combinations of the 4 digits in the 4 digit numbers.  For instance, we might arrange the 4 digits into the 24 combinations using a SQL statement like the following (the numbers represent the original positions of the digits): 
&lt;pre&gt;
WITH N AS
  (SELECT
    ROWNUM RN
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=4)
SELECT
  N1.RN P1,
  N2.RN P2,
  N3.RN P3,
  N4.RN P4
FROM
  N N1,
  N N2,
  N N3,
  N N4
WHERE
  N1.RN&lt;&gt;N2.RN
  AND N1.RN&lt;&gt;N3.RN
  AND N1.RN&lt;&gt;N4.RN
  AND N2.RN&lt;&gt;N3.RN
  AND N2.RN&lt;&gt;N4.RN
  AND N3.RN&lt;&gt;N4.RN
ORDER BY
  P1,
  P2,
  P3,
  P4;
 
 P1  P2  P3  P4
--- --- --- ---
  1   2   3   4
  1   2   4   3
  1   3   2   4
  1   3   4   2
  1   4   2   3
  1   4   3   2
  2   1   3   4
  2   1   4   3
  2   3   1   4
  2   3   4   1
  2   4   1   3
  2   4   3   1
  3   1   2   4
  3   1   4   2
  3   2   1   4
  3   2   4   1
  3   4   1   2
  3   4   2   1
  4   1   2   3
  4   1   3   2
  4   2   1   3
  4   2   3   1
  4   3   1   2
  4   3   2   1
 
24 rows selected.
&lt;/pre&gt;

Now for the easy part, use the above matrix to simply pull out the digits in the specified order from the list of numbers between 1000 and 9999:
&lt;pre&gt;
SELECT DISTINCT
  *
FROM
(SELECT
  N.RN,
  TO_NUMBER(SUBSTR(N.RNC,P.P1,1)&#124;&#124;SUBSTR(N.RNC,P.P2,1)&#124;&#124;SUBSTR(N.RNC,P.P3,1)&#124;&#124;SUBSTR(N.RNC,P.P4,1)) RND
FROM
  (SELECT
    ROWNUM+1000 RN,
    TO_CHAR(ROWNUM+1000) RNC
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=8999) N,
  (WITH N AS
    (SELECT
      ROWNUM RN
    FROM
      DUAL
    CONNECT BY
      LEVEL&lt;=4)
  SELECT
    N1.RN P1,
    N2.RN P2,
    N3.RN P3,
    N4.RN P4
  FROM
    N N1,
    N N2,
    N N3,
    N N4
  WHERE
    N1.RN&lt;&gt;N2.RN
    AND N1.RN&lt;&gt;N3.RN
    AND N1.RN&lt;&gt;N4.RN
    AND N2.RN&lt;&gt;N3.RN
    AND N2.RN&lt;&gt;N4.RN
    AND N3.RN&lt;&gt;N4.RN) P
WHERE
  RN/10&lt;&gt;TRUNC(RN/10))
WHERE
  RN&lt;&gt;RND
  AND RN/RND=TRUNC(RN/RND)
ORDER BY
  RN,
  RND;
 
   RN   RND
----- -----
 1001    11
 1005    15
 1008    18
 1053   351
 2002    22
 2016   126
 2025   225
 2079   297
 2106   162
 3003    33
 3024   432
 3042   234
 3045   435
 3105   135
 3105  1035
 3402   243
 4004    44
 4005    45
 5005    55
 5049   459
 6006    66
 6031   163
 6045   465
 6048   864
 6072   276
 6075   675
 6084   468
 6105   165
 6804   486
 7007    77
 7011   171
 7128  1782
 7425  2475
 8008    88
 8019   891
 8092   289
 8316  1386
 8712  2178
 9009    99
 9016   196
 9021   291
 9108   198
 9207   279
 9207   297
 9405   495
 9504   594
 9513  1359
 9801   891
 9801  1089

49 rows selected.
&lt;/pre&gt;

Any other solutions?]]></description>
		<content:encoded><![CDATA[<p>There have been a couple of possible solutions posted so far, and there has been no more suggestions posted in the last 36 hours, so I thought that I would share the solution that I developed.</p>
<p>First, we need to find a way to build all 24 combinations of the 4 digits in the 4 digit numbers.  For instance, we might arrange the 4 digits into the 24 combinations using a SQL statement like the following (the numbers represent the original positions of the digits): </p>
<pre>
WITH N AS
  (SELECT
    ROWNUM RN
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=4)
SELECT
  N1.RN P1,
  N2.RN P2,
  N3.RN P3,
  N4.RN P4
FROM
  N N1,
  N N2,
  N N3,
  N N4
WHERE
  N1.RN&lt;&gt;N2.RN
  AND N1.RN&lt;&gt;N3.RN
  AND N1.RN&lt;&gt;N4.RN
  AND N2.RN&lt;&gt;N3.RN
  AND N2.RN&lt;&gt;N4.RN
  AND N3.RN&lt;&gt;N4.RN
ORDER BY
  P1,
  P2,
  P3,
  P4;
 
 P1  P2  P3  P4
--- --- --- ---
  1   2   3   4
  1   2   4   3
  1   3   2   4
  1   3   4   2
  1   4   2   3
  1   4   3   2
  2   1   3   4
  2   1   4   3
  2   3   1   4
  2   3   4   1
  2   4   1   3
  2   4   3   1
  3   1   2   4
  3   1   4   2
  3   2   1   4
  3   2   4   1
  3   4   1   2
  3   4   2   1
  4   1   2   3
  4   1   3   2
  4   2   1   3
  4   2   3   1
  4   3   1   2
  4   3   2   1
 
24 rows selected.
</pre>
<p>Now for the easy part, use the above matrix to simply pull out the digits in the specified order from the list of numbers between 1000 and 9999:</p>
<pre>
SELECT DISTINCT
  *
FROM
(SELECT
  N.RN,
  TO_NUMBER(SUBSTR(N.RNC,P.P1,1)||SUBSTR(N.RNC,P.P2,1)||SUBSTR(N.RNC,P.P3,1)||SUBSTR(N.RNC,P.P4,1)) RND
FROM
  (SELECT
    ROWNUM+1000 RN,
    TO_CHAR(ROWNUM+1000) RNC
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=8999) N,
  (WITH N AS
    (SELECT
      ROWNUM RN
    FROM
      DUAL
    CONNECT BY
      LEVEL&lt;=4)
  SELECT
    N1.RN P1,
    N2.RN P2,
    N3.RN P3,
    N4.RN P4
  FROM
    N N1,
    N N2,
    N N3,
    N N4
  WHERE
    N1.RN&lt;&gt;N2.RN
    AND N1.RN&lt;&gt;N3.RN
    AND N1.RN&lt;&gt;N4.RN
    AND N2.RN&lt;&gt;N3.RN
    AND N2.RN&lt;&gt;N4.RN
    AND N3.RN&lt;&gt;N4.RN) P
WHERE
  RN/10&lt;&gt;TRUNC(RN/10))
WHERE
  RN&lt;&gt;RND
  AND RN/RND=TRUNC(RN/RND)
ORDER BY
  RN,
  RND;
 
   RN   RND
----- -----
 1001    11
 1005    15
 1008    18
 1053   351
 2002    22
 2016   126
 2025   225
 2079   297
 2106   162
 3003    33
 3024   432
 3042   234
 3045   435
 3105   135
 3105  1035
 3402   243
 4004    44
 4005    45
 5005    55
 5049   459
 6006    66
 6031   163
 6045   465
 6048   864
 6072   276
 6075   675
 6084   468
 6105   165
 6804   486
 7007    77
 7011   171
 7128  1782
 7425  2475
 8008    88
 8019   891
 8092   289
 8316  1386
 8712  2178
 9009    99
 9016   196
 9021   291
 9108   198
 9207   279
 9207   297
 9405   495
 9504   594
 9513  1359
 9801   891
 9801  1089

49 rows selected.
</pre>
<p>Any other solutions?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: utecistu</title>
		<link>http://hoopercharles.wordpress.com/2011/08/02/the-new-order-oracle-coding-challenge-2/#comment-3741</link>
		<dc:creator><![CDATA[utecistu]]></dc:creator>
		<pubDate>Tue, 02 Aug 2011 15:24:24 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5232#comment-3741</guid>
		<description><![CDATA[sorry about incovenience. here are the original 2 replies (unaltered):
1:[code]

select * from (
    select nr original,
           to_number(substr(ch,d1,1)&#124;&#124;substr(ch,d2,1)&#124;&#124;substr(ch,d3,1)&#124;&#124;substr(ch,d4,1)) combination
    from
        (select d1,d2,d3,d4 from
         (select level d1 from dual connect by level&lt;=4),
         (select level d2 from dual connect by level&lt;=4),
         (select level d3 from dual connect by level&lt;=4),
         (select level d4 from dual connect by level&lt;=4)
        where d1!=d2 and d1!=d3 and d1!=d4 and d2!=d3 and d2!=d4 and d3!=d4 and (d1,d2,d3,d4) not in(select 1,2,3,4 from dual)
        ) comb,
        (select * from (select level nr, to_char(level) ch from dual connect by level&lt;=9999) where nr&gt;1000 and mod(nr,10)!=0) numbers 
    where mod(nr, to_number(substr(ch,d1,1)&#124;&#124;substr(ch,d2,1)&#124;&#124;substr(ch,d3,1)&#124;&#124;substr(ch,d4,1)))=0 and substr(ch,d1,1)!=&#039;0&#039;
)
where original!=combination
[/code]
2:[code]
select * from (
    select nr original,
           to_number(substr(ch,d1,1)&#124;&#124;substr(ch,d2,1)&#124;&#124;substr(ch,d3,1)&#124;&#124;substr(ch,d4,1)) combination 
    from 
        (select substr(ch,2,1) d1,substr(ch,4,1) d2,substr(ch,6,1) d3,substr(ch,8,1) d4 from 
            (select SYS_CONNECT_BY_PATH(5-l,&#039; &#039;) ch from (select level l from dual connect by level&lt;=4) 
             connect by nocycle prior l&lt;5)  
        where length(ch)=8 and ch!=&#039; 1 2 3 4&#039;
        ) digits,
        (select * from (select level nr, to_char(level) ch from dual connect by level&lt;=9999) where nr&gt;1000 and mod(nr,10)!=0) numbers 
    where substr(ch,d1,1)!=&#039;0&#039;
)
where original!=combination and mod(original, combination)=0 
[/code]

p.s. pls delete the older ones]]></description>
		<content:encoded><![CDATA[<p>sorry about incovenience. here are the original 2 replies (unaltered):<br />
1:
<pre class="brush: plain; title: ; notranslate">

select * from (
    select nr original,
           to_number(substr(ch,d1,1)||substr(ch,d2,1)||substr(ch,d3,1)||substr(ch,d4,1)) combination
    from
        (select d1,d2,d3,d4 from
         (select level d1 from dual connect by level&lt;=4),
         (select level d2 from dual connect by level&lt;=4),
         (select level d3 from dual connect by level&lt;=4),
         (select level d4 from dual connect by level&lt;=4)
        where d1!=d2 and d1!=d3 and d1!=d4 and d2!=d3 and d2!=d4 and d3!=d4 and (d1,d2,d3,d4) not in(select 1,2,3,4 from dual)
        ) comb,
        (select * from (select level nr, to_char(level) ch from dual connect by level&lt;=9999) where nr&gt;1000 and mod(nr,10)!=0) numbers 
    where mod(nr, to_number(substr(ch,d1,1)||substr(ch,d2,1)||substr(ch,d3,1)||substr(ch,d4,1)))=0 and substr(ch,d1,1)!='0'
)
where original!=combination
</pre>
<p>2:
<pre class="brush: plain; title: ; notranslate">
select * from (
    select nr original,
           to_number(substr(ch,d1,1)||substr(ch,d2,1)||substr(ch,d3,1)||substr(ch,d4,1)) combination 
    from 
        (select substr(ch,2,1) d1,substr(ch,4,1) d2,substr(ch,6,1) d3,substr(ch,8,1) d4 from 
            (select SYS_CONNECT_BY_PATH(5-l,' ') ch from (select level l from dual connect by level&lt;=4) 
             connect by nocycle prior l&lt;5)  
        where length(ch)=8 and ch!=' 1 2 3 4'
        ) digits,
        (select * from (select level nr, to_char(level) ch from dual connect by level&lt;=9999) where nr&gt;1000 and mod(nr,10)!=0) numbers 
    where substr(ch,d1,1)!='0'
)
where original!=combination and mod(original, combination)=0 
</pre>
<p>p.s. pls delete the older ones</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RJ</title>
		<link>http://hoopercharles.wordpress.com/2011/08/02/the-new-order-oracle-coding-challenge-2/#comment-3736</link>
		<dc:creator><![CDATA[RJ]]></dc:creator>
		<pubDate>Tue, 02 Aug 2011 14:48:46 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5232#comment-3736</guid>
		<description><![CDATA[I think i am missing at-last one more combinations (9009 and 0099), will check my code (it is w-i-p).]]></description>
		<content:encoded><![CDATA[<p>I think i am missing at-last one more combinations (9009 and 0099), will check my code (it is w-i-p).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RJ</title>
		<link>http://hoopercharles.wordpress.com/2011/08/02/the-new-order-oracle-coding-challenge-2/#comment-3735</link>
		<dc:creator><![CDATA[RJ]]></dc:creator>
		<pubDate>Tue, 02 Aug 2011 14:36:03 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5232#comment-3735</guid>
		<description><![CDATA[Here is my attempt ...  as mentioned in the code, Anagram credit goes to Laurent. Due to use of pl/sql, this is not a pure-sql solution but at-least an attempt.

&lt;pre&gt;
-- anagram code taken from Laurent Schneider&#039;s Anagram solution posted at 
-- url http://forums.oracle.com/forums/thread.jspa?messageID=1791550
-- shamelessly reused with full credit to Laurent for that code. Hope he won&#039;t mind the reuse ... :)
--
-- we treat numbers as char to generate anagrams (as possible combinations)
-- raj (rjamya@gmail.com)
-- please suggest anything i missed or improvements
-- 
create or replace type table_of_varchar2 as table of varchar2(255);
/ 
create or replace package anagram is
    procedure p(x varchar2, y varchar2 default null);
    function f(x varchar2) return table_of_varchar2;
end;
/ 
create or replace package body anagram is
    t table_of_varchar2;
    procedure p(x varchar2, y varchar2 default null) is
    begin
        if (length(x) = 1) then
            t.extend(1);
            t(t.last):=y&#124;&#124;x;
        else
            for i in 1..length(x) loop
                p(substr(x,1,i-1)&#124;&#124;substr(x,i+1),y&#124;&#124;substr(x,i,1));
            end loop;
        end if;
    end p;
 
    function f(x varchar2) return table_of_varchar2 is
    begin
        t := new table_of_varchar2();
        p(x);
        return t;
    end f;

end;
/ 
set timing on
declare
procedure p (p_msg in varchar2) is
begin 
  -- dbms_output.put_line(to_char(systimestamp,&#039;hh24:mi:ss.ff6&#039;) &#124;&#124; &#039;: &#039; &#124;&#124; p_msg);
  dbms_output.put_line(p_msg);
end;
--
begin
  p(&#039;Original  Combination&#039;);
  p(&#039;--------  -----------&#039;);
  for f in (select r r0 from (select rownum r from dual connect by level = 1000 and mod(r,10)  0)
  loop
    for a in (select distinct column_value as c0 from table(anagram.f(f.r0)))
    loop
      if    f.r0  a.c0 
        and f.r0 &gt; a.c0
        and mod(f.r0,a.c0) = 0 then
        -- p(f.r0 &#124;&#124; &#039; : &#039; &#124;&#124; a.c0 &#124;&#124; &#039; : &#039; &#124;&#124; (f.r0/a.c0));
    p(lpad(f.r0,8,&#039; &#039;) &#124;&#124; &#039;  &#039; &#124;&#124; lpad(a.c0,11,&#039; &#039;));
      end if;
    end loop ;
  end loop;
end;
/  
commit
/
Output is ... 

Original  Combination
--------  -----------
    1001         0011
    1005         0015
    1008         0018
    1053         0351
    2002         0022
    2016         0126
    2025         0225
    2079         0297
    2106         0162
    3003         0033
    3024         0432
    3042         0234
    3045         0435
    3105         0135
    3105         1035
    3402         0243
    4004         0044
    4005         0045
    5005         0055
    5049         0459
    6006         0066
    6031         0163
    6045         0465
    6048         0864
    6072         0276
    6075         0675
    6084         0468
    6105         0165
    6804         0486
    7007         0077
    7011         0171
    7128         1782
    7425         2475
    8008         0088
    8019         0891
    8092         0289
    8316         1386
    8712         2178
    9009         0099
    9016         0196
    9021         0291
    9108         0198
    9207         0279
    9207         0297
    9405         0495
    9504         0594
    9513         1359
    9801         0891
    9801         1089
&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>Here is my attempt &#8230;  as mentioned in the code, Anagram credit goes to Laurent. Due to use of pl/sql, this is not a pure-sql solution but at-least an attempt.</p>
<pre>
-- anagram code taken from Laurent Schneider's Anagram solution posted at 
-- url <a href="http://forums.oracle.com/forums/thread.jspa?messageID=1791550" rel="nofollow">http://forums.oracle.com/forums/thread.jspa?messageID=1791550</a>
-- shamelessly reused with full credit to Laurent for that code. Hope he won't mind the reuse ... <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> 
--
-- we treat numbers as char to generate anagrams (as possible combinations)
-- raj (rjamya@gmail.com)
-- please suggest anything i missed or improvements
-- 
create or replace type table_of_varchar2 as table of varchar2(255);
/ 
create or replace package anagram is
    procedure p(x varchar2, y varchar2 default null);
    function f(x varchar2) return table_of_varchar2;
end;
/ 
create or replace package body anagram is
    t table_of_varchar2;
    procedure p(x varchar2, y varchar2 default null) is
    begin
        if (length(x) = 1) then
            t.extend(1);
            t(t.last):=y||x;
        else
            for i in 1..length(x) loop
                p(substr(x,1,i-1)||substr(x,i+1),y||substr(x,i,1));
            end loop;
        end if;
    end p;
 
    function f(x varchar2) return table_of_varchar2 is
    begin
        t := new table_of_varchar2();
        p(x);
        return t;
    end f;

end;
/ 
set timing on
declare
procedure p (p_msg in varchar2) is
begin 
  -- dbms_output.put_line(to_char(systimestamp,'hh24:mi:ss.ff6') || ': ' || p_msg);
  dbms_output.put_line(p_msg);
end;
--
begin
  p('Original  Combination');
  p('--------  -----------');
  for f in (select r r0 from (select rownum r from dual connect by level = 1000 and mod(r,10)  0)
  loop
    for a in (select distinct column_value as c0 from table(anagram.f(f.r0)))
    loop
      if    f.r0  a.c0 
        and f.r0 &gt; a.c0
        and mod(f.r0,a.c0) = 0 then
        -- p(f.r0 || ' : ' || a.c0 || ' : ' || (f.r0/a.c0));
    p(lpad(f.r0,8,' ') || '  ' || lpad(a.c0,11,' '));
      end if;
    end loop ;
  end loop;
end;
/  
commit
/
Output is ... 

Original  Combination
--------  -----------
    1001         0011
    1005         0015
    1008         0018
    1053         0351
    2002         0022
    2016         0126
    2025         0225
    2079         0297
    2106         0162
    3003         0033
    3024         0432
    3042         0234
    3045         0435
    3105         0135
    3105         1035
    3402         0243
    4004         0044
    4005         0045
    5005         0055
    5049         0459
    6006         0066
    6031         0163
    6045         0465
    6048         0864
    6072         0276
    6075         0675
    6084         0468
    6105         0165
    6804         0486
    7007         0077
    7011         0171
    7128         1782
    7425         2475
    8008         0088
    8019         0891
    8092         0289
    8316         1386
    8712         2178
    9009         0099
    9016         0196
    9021         0291
    9108         0198
    9207         0279
    9207         0297
    9405         0495
    9504         0594
    9513         1359
    9801         0891
    9801         1089
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>
