<?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 1</title>
	<atom:link href="http://hoopercharles.wordpress.com/2011/07/31/the-new-order-oracle-coding-challenge-1/feed/" rel="self" type="application/rss+xml" />
	<link>http://hoopercharles.wordpress.com/2011/07/31/the-new-order-oracle-coding-challenge-1/</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/07/31/the-new-order-oracle-coding-challenge-1/#comment-3744</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Wed, 03 Aug 2011 11:09:56 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5210#comment-3744</guid>
		<description><![CDATA[Mohamed,

Very nice solution.  What you put together shares some similarities with the solution provided by Dominic Delmolino, and one of the solutions that I posted.

Any thoughts on part 2 of the series?:
http://hoopercharles.wordpress.com/2011/08/02/the-new-order-oracle-coding-challenge-2/]]></description>
		<content:encoded><![CDATA[<p>Mohamed,</p>
<p>Very nice solution.  What you put together shares some similarities with the solution provided by Dominic Delmolino, and one of the solutions that I posted.</p>
<p>Any thoughts on part 2 of the series?:<br />
<a href="http://hoopercharles.wordpress.com/2011/08/02/the-new-order-oracle-coding-challenge-2/" rel="nofollow">http://hoopercharles.wordpress.com/2011/08/02/the-new-order-oracle-coding-challenge-2/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Houri Mohamed</title>
		<link>http://hoopercharles.wordpress.com/2011/07/31/the-new-order-oracle-coding-challenge-1/#comment-3743</link>
		<dc:creator><![CDATA[Houri Mohamed]]></dc:creator>
		<pubDate>Wed, 03 Aug 2011 08:20:06 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5210#comment-3743</guid>
		<description><![CDATA[&lt;pre&gt;
SELECT id, rev_id
from
  ( select rownum id 
          ,to_number(reverse(to_char(rownum))) rev_id
    FROM dual CONNECT BY level &lt;= 1000000
  )
where mod (id, 10) != 0
and   mod(id, rev_id) = 0 
and   id != rev_id
&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<pre>
SELECT id, rev_id
from
  ( select rownum id 
          ,to_number(reverse(to_char(rownum))) rev_id
    FROM dual CONNECT BY level &lt;= 1000000
  )
where mod (id, 10) != 0
and   mod(id, rev_id) = 0 
and   id != rev_id
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://hoopercharles.wordpress.com/2011/07/31/the-new-order-oracle-coding-challenge-1/#comment-3732</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Mon, 01 Aug 2011 20:19:02 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5210#comment-3732</guid>
		<description><![CDATA[Here is another example that uses recursion to reverse the order of the digits.  On Oracle Database 11.2.0.2, this returns an error if there are more than 3 digits in the number:
&lt;pre&gt;
WITH N AS
  (SELECT
    ROWNUM N,
    TO_CHAR(ROWNUM) RN
  FROM
    DUAL
  CONNECT BY
    LEVEL &lt;= 1000),
 R (N, RN2, TEMP) AS
  (SELECT
    N.N,
    SUBSTR(RN,-1) RN2,
    SUBSTR(RN,1,LENGTH(RN)-1) TEMP
  FROM
    N
  UNION ALL
  SELECT
    R.N,
    R.RN2 &#124;&#124; SUBSTR(R.TEMP,-1) RN2,
    SUBSTR(R.TEMP,1,LENGTH(R.TEMP)-1) TEMP
  FROM
    R
  WHERE
    R.TEMP IS NOT NULL)
SELECT
  N,
  TO_NUMBER(RN2) RN
FROM
  R
WHERE
  TEMP IS NULL;
 
         N        RN
---------- ---------
         1         1
         2         2
         3         3
         4         4
         5         5
         6         6
         7         7
         8         8
         9         9
        10         1
        11        11
        12        21
        13        31
...
       987       789
       988       889
       989       989
       990        99
ERROR:
ORA-01489: result of string concatenation is too long
&lt;/pre&gt;

The same error is returned if we precreate a table:
&lt;pre&gt;
CREATE TABLE T5 AS
SELECT
  ROWNUM N,
  TO_CHAR(ROWNUM) RN
FROM
  DUAL
CONNECT BY
  LEVEL &lt;= 1000;
 
WITH N AS
  (SELECT
    N,
    RN
  FROM
    T5),
 R (N, RN2, TEMP) AS
  (SELECT
    N.N,
    SUBSTR(RN,-1) RN2,
    SUBSTR(RN,1,LENGTH(RN)-1) TEMP
  FROM
    N
  UNION ALL
  SELECT
    R.N,
    R.RN2 &#124;&#124; SUBSTR(R.TEMP,-1) RN2,
    SUBSTR(R.TEMP,1,LENGTH(R.TEMP)-1) TEMP
  FROM
    R
  WHERE
    R.TEMP IS NOT NULL)
SELECT
  N,
  TO_NUMBER(RN2) RN
FROM
  R
WHERE
  TEMP IS NULL;
&lt;/pre&gt;

Trying a 4 digit number:
&lt;pre&gt;
WITH
 R (N, RN2, TEMP) AS
  (SELECT
    N.N,
    SUBSTR(RN,-1) RN2,
    SUBSTR(RN,1,LENGTH(RN)-1) TEMP
  FROM
    T5 N
  WHERE
    N=1000
  UNION ALL
  SELECT
    R.N,
    R.RN2 &#124;&#124; SUBSTR(R.TEMP,-1) RN2,
    SUBSTR(R.TEMP,1,LENGTH(R.TEMP)-1) TEMP
  FROM
    R
  WHERE
    R.TEMP IS NOT NULL)
SELECT
  N,
  TO_NUMBER(RN2) RN
FROM
  R
WHERE
  TEMP IS NULL;
&lt;/pre&gt;

Recursion in this case is apparently possible on SQL Server, as found in this SQL Server forum thread:
http://www.sqlservercentral.com/Forums/Topic697178-23-1.aspx

Is there a work-around that allows a recursion approach to work on Oracle Database?]]></description>
		<content:encoded><![CDATA[<p>Here is another example that uses recursion to reverse the order of the digits.  On Oracle Database 11.2.0.2, this returns an error if there are more than 3 digits in the number:</p>
<pre>
WITH N AS
  (SELECT
    ROWNUM N,
    TO_CHAR(ROWNUM) RN
  FROM
    DUAL
  CONNECT BY
    LEVEL &lt;= 1000),
 R (N, RN2, TEMP) AS
  (SELECT
    N.N,
    SUBSTR(RN,-1) RN2,
    SUBSTR(RN,1,LENGTH(RN)-1) TEMP
  FROM
    N
  UNION ALL
  SELECT
    R.N,
    R.RN2 || SUBSTR(R.TEMP,-1) RN2,
    SUBSTR(R.TEMP,1,LENGTH(R.TEMP)-1) TEMP
  FROM
    R
  WHERE
    R.TEMP IS NOT NULL)
SELECT
  N,
  TO_NUMBER(RN2) RN
FROM
  R
WHERE
  TEMP IS NULL;
 
         N        RN
---------- ---------
         1         1
         2         2
         3         3
         4         4
         5         5
         6         6
         7         7
         8         8
         9         9
        10         1
        11        11
        12        21
        13        31
...
       987       789
       988       889
       989       989
       990        99
ERROR:
ORA-01489: result of string concatenation is too long
</pre>
<p>The same error is returned if we precreate a table:</p>
<pre>
CREATE TABLE T5 AS
SELECT
  ROWNUM N,
  TO_CHAR(ROWNUM) RN
FROM
  DUAL
CONNECT BY
  LEVEL &lt;= 1000;
 
WITH N AS
  (SELECT
    N,
    RN
  FROM
    T5),
 R (N, RN2, TEMP) AS
  (SELECT
    N.N,
    SUBSTR(RN,-1) RN2,
    SUBSTR(RN,1,LENGTH(RN)-1) TEMP
  FROM
    N
  UNION ALL
  SELECT
    R.N,
    R.RN2 || SUBSTR(R.TEMP,-1) RN2,
    SUBSTR(R.TEMP,1,LENGTH(R.TEMP)-1) TEMP
  FROM
    R
  WHERE
    R.TEMP IS NOT NULL)
SELECT
  N,
  TO_NUMBER(RN2) RN
FROM
  R
WHERE
  TEMP IS NULL;
</pre>
<p>Trying a 4 digit number:</p>
<pre>
WITH
 R (N, RN2, TEMP) AS
  (SELECT
    N.N,
    SUBSTR(RN,-1) RN2,
    SUBSTR(RN,1,LENGTH(RN)-1) TEMP
  FROM
    T5 N
  WHERE
    N=1000
  UNION ALL
  SELECT
    R.N,
    R.RN2 || SUBSTR(R.TEMP,-1) RN2,
    SUBSTR(R.TEMP,1,LENGTH(R.TEMP)-1) TEMP
  FROM
    R
  WHERE
    R.TEMP IS NOT NULL)
SELECT
  N,
  TO_NUMBER(RN2) RN
FROM
  R
WHERE
  TEMP IS NULL;
</pre>
<p>Recursion in this case is apparently possible on SQL Server, as found in this SQL Server forum thread:<br />
<a href="http://www.sqlservercentral.com/Forums/Topic697178-23-1.aspx" rel="nofollow">http://www.sqlservercentral.com/Forums/Topic697178-23-1.aspx</a></p>
<p>Is there a work-around that allows a recursion approach to work on Oracle Database?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://hoopercharles.wordpress.com/2011/07/31/the-new-order-oracle-coding-challenge-1/#comment-3731</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Mon, 01 Aug 2011 19:23:35 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5210#comment-3731</guid>
		<description><![CDATA[Another example that probably will not work with all NLS settings.  DUMP the value of the string version of the number, examine the dump value after the colon (:), and use REGEXP_SUBSTR to pick out the &quot;words&quot; (numbers) from the comma separated list that remains.  The final step converts the numbers back into ASCII characters with the CHR function:
&lt;pre&gt;
SELECT
  N,
  TO_NUMBER(
    CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,&#039;:&#039;)+2),&#039;\w+&#039;,1,10))&#124;&#124;
    CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,&#039;:&#039;)+2),&#039;\w+&#039;,1,9))&#124;&#124;
    CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,&#039;:&#039;)+2),&#039;\w+&#039;,1,8))&#124;&#124;
    CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,&#039;:&#039;)+2),&#039;\w+&#039;,1,7))&#124;&#124;
    CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,&#039;:&#039;)+2),&#039;\w+&#039;,1,6))&#124;&#124;
    CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,&#039;:&#039;)+2),&#039;\w+&#039;,1,5))&#124;&#124;
    CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,&#039;:&#039;)+2),&#039;\w+&#039;,1,4))&#124;&#124;
    CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,&#039;:&#039;)+2),&#039;\w+&#039;,1,3))&#124;&#124;
    CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,&#039;:&#039;)+2),&#039;\w+&#039;,1,2))&#124;&#124;
    CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,&#039;:&#039;)+2),&#039;\w+&#039;,1,1))) RN,
  D
FROM
  (SELECT
    ROWNUM N,
    DUMP(TO_CHAR(ROWNUM)) D
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=1000);
 
         N        RN D
---------- --------- ------------------
         1         1 Typ=1 Len=1: 49
         2         2 Typ=1 Len=1: 50
         3         3 Typ=1 Len=1: 51
         4         4 Typ=1 Len=1: 52
         5         5 Typ=1 Len=1: 53
         6         6 Typ=1 Len=1: 54
         7         7 Typ=1 Len=1: 55
         8         8 Typ=1 Len=1: 56
         9         9 Typ=1 Len=1: 57
        10         1 Typ=1 Len=2: 49,48
        11        11 Typ=1 Len=2: 49,49
        12        21 Typ=1 Len=2: 49,50
        13        31 Typ=1 Len=2: 49,51
...
       995       599 Typ=1 Len=3: 57,57,53
       996       699 Typ=1 Len=3: 57,57,54
       997       799 Typ=1 Len=3: 57,57,55
       998       899 Typ=1 Len=3: 57,57,56
       999       999 Typ=1 Len=3: 57,57,57
      1000         1 Typ=1 Len=4: 49,48,48,48
&lt;/pre&gt;

Next, we slide the above into an inline view and apply the conditions:
&lt;pre&gt;
SELECT
  N,
  RN,
  N/RN DIV
FROM
  (SELECT
    N,
    TO_NUMBER(
      CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,&#039;:&#039;)+2),&#039;\w+&#039;,1,10))&#124;&#124;
      CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,&#039;:&#039;)+2),&#039;\w+&#039;,1,9))&#124;&#124;
      CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,&#039;:&#039;)+2),&#039;\w+&#039;,1,8))&#124;&#124;
      CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,&#039;:&#039;)+2),&#039;\w+&#039;,1,7))&#124;&#124;
      CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,&#039;:&#039;)+2),&#039;\w+&#039;,1,6))&#124;&#124;
      CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,&#039;:&#039;)+2),&#039;\w+&#039;,1,5))&#124;&#124;
      CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,&#039;:&#039;)+2),&#039;\w+&#039;,1,4))&#124;&#124;
      CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,&#039;:&#039;)+2),&#039;\w+&#039;,1,3))&#124;&#124;
      CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,&#039;:&#039;)+2),&#039;\w+&#039;,1,2))&#124;&#124;
      CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,&#039;:&#039;)+2),&#039;\w+&#039;,1,1))) RN
  FROM
    (SELECT
      ROWNUM N,
      DUMP(TO_CHAR(ROWNUM)) D
    FROM
      DUAL
    CONNECT BY
      LEVEL&lt;=1000000))
WHERE
  N/10 &lt;&gt; TRUNC(N/10)
  AND N/RN=TRUNC(N/RN)
  AND N &gt; RN;
&lt;/pre&gt;

Note the number of times the SUBSTR(D,INSTR(D,&#039;:&#039;)+2) value is calculated - for better performance, that value should have been calculated in the inline view where DUMP(TO_CHAR(ROWNUM)) is performed.]]></description>
		<content:encoded><![CDATA[<p>Another example that probably will not work with all NLS settings.  DUMP the value of the string version of the number, examine the dump value after the colon (:), and use REGEXP_SUBSTR to pick out the &#8220;words&#8221; (numbers) from the comma separated list that remains.  The final step converts the numbers back into ASCII characters with the CHR function:</p>
<pre>
SELECT
  N,
  TO_NUMBER(
    CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,':')+2),'\w+',1,10))||
    CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,':')+2),'\w+',1,9))||
    CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,':')+2),'\w+',1,8))||
    CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,':')+2),'\w+',1,7))||
    CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,':')+2),'\w+',1,6))||
    CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,':')+2),'\w+',1,5))||
    CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,':')+2),'\w+',1,4))||
    CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,':')+2),'\w+',1,3))||
    CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,':')+2),'\w+',1,2))||
    CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,':')+2),'\w+',1,1))) RN,
  D
FROM
  (SELECT
    ROWNUM N,
    DUMP(TO_CHAR(ROWNUM)) D
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=1000);
 
         N        RN D
---------- --------- ------------------
         1         1 Typ=1 Len=1: 49
         2         2 Typ=1 Len=1: 50
         3         3 Typ=1 Len=1: 51
         4         4 Typ=1 Len=1: 52
         5         5 Typ=1 Len=1: 53
         6         6 Typ=1 Len=1: 54
         7         7 Typ=1 Len=1: 55
         8         8 Typ=1 Len=1: 56
         9         9 Typ=1 Len=1: 57
        10         1 Typ=1 Len=2: 49,48
        11        11 Typ=1 Len=2: 49,49
        12        21 Typ=1 Len=2: 49,50
        13        31 Typ=1 Len=2: 49,51
...
       995       599 Typ=1 Len=3: 57,57,53
       996       699 Typ=1 Len=3: 57,57,54
       997       799 Typ=1 Len=3: 57,57,55
       998       899 Typ=1 Len=3: 57,57,56
       999       999 Typ=1 Len=3: 57,57,57
      1000         1 Typ=1 Len=4: 49,48,48,48
</pre>
<p>Next, we slide the above into an inline view and apply the conditions:</p>
<pre>
SELECT
  N,
  RN,
  N/RN DIV
FROM
  (SELECT
    N,
    TO_NUMBER(
      CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,':')+2),'\w+',1,10))||
      CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,':')+2),'\w+',1,9))||
      CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,':')+2),'\w+',1,8))||
      CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,':')+2),'\w+',1,7))||
      CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,':')+2),'\w+',1,6))||
      CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,':')+2),'\w+',1,5))||
      CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,':')+2),'\w+',1,4))||
      CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,':')+2),'\w+',1,3))||
      CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,':')+2),'\w+',1,2))||
      CHR(REGEXP_SUBSTR(SUBSTR(D,INSTR(D,':')+2),'\w+',1,1))) RN
  FROM
    (SELECT
      ROWNUM N,
      DUMP(TO_CHAR(ROWNUM)) D
    FROM
      DUAL
    CONNECT BY
      LEVEL&lt;=1000000))
WHERE
  N/10 &lt;&gt; TRUNC(N/10)
  AND N/RN=TRUNC(N/RN)
  AND N &gt; RN;
</pre>
<p>Note the number of times the SUBSTR(D,INSTR(D,&#8217;:')+2) value is calculated &#8211; for better performance, that value should have been calculated in the inline view where DUMP(TO_CHAR(ROWNUM)) is performed.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://hoopercharles.wordpress.com/2011/07/31/the-new-order-oracle-coding-challenge-1/#comment-3730</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Mon, 01 Aug 2011 18:49:43 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5210#comment-3730</guid>
		<description><![CDATA[Another method - use mathematics to reverse the digits in the numbers - the DECODE and SIGN conbination make certain that we do not accidentally pad additional zeros at the end of the reversed number:
&lt;pre&gt;
SELECT
  ROWNUM N,
  TO_NUMBER(
    TO_CHAR(MOD(ROWNUM,10)) &#124;&#124;
    TO_CHAR(DECODE(SIGN(ROWNUM-10),-1,&#039;&#039;,MOD(TRUNC(ROWNUM/10),10))) &#124;&#124;
    TO_CHAR(DECODE(SIGN(ROWNUM-100),-1,&#039;&#039;,MOD(TRUNC(ROWNUM/100),10))) &#124;&#124;
    TO_CHAR(DECODE(SIGN(ROWNUM-1000),-1,&#039;&#039;,MOD(TRUNC(ROWNUM/1000),10))) &#124;&#124;
    TO_CHAR(DECODE(SIGN(ROWNUM-10000),-1,&#039;&#039;,MOD(TRUNC(ROWNUM/10000),10))) &#124;&#124;
    TO_CHAR(DECODE(SIGN(ROWNUM-100000),-1,&#039;&#039;,MOD(TRUNC(ROWNUM/100000),10))) &#124;&#124;
    TO_CHAR(DECODE(SIGN(ROWNUM-1000000),-1,&#039;&#039;,MOD(TRUNC(ROWNUM/1000000),10))) &#124;&#124;
    TO_CHAR(DECODE(SIGN(ROWNUM-10000000),-1,&#039;&#039;,MOD(TRUNC(ROWNUM/10000000),10))) &#124;&#124;
    TO_CHAR(DECODE(SIGN(ROWNUM-100000000),-1,&#039;&#039;,MOD(TRUNC(ROWNUM/100000000),10)))) RN
FROM
  DUAL
CONNECT BY
  LEVEL&lt;=1000;
 
---------- ---------
         1         1
         2         2
         3         3
         4         4
         5         5
         6         6
         7         7
         8         8
         9         9
        10         1
        11        11
        12        21
        13        31
...
       996       699
       997       799
       998       899
       999       999
      1000         1
&lt;/pre&gt;

Then slide the above into an inline view to perform the tests:
&lt;pre&gt;
SELECT
  N,
  RN,
  N/RN DIV
FROM
  (SELECT
    ROWNUM N,
    TO_NUMBER(
      TO_CHAR(MOD(ROWNUM,10)) &#124;&#124;
      TO_CHAR(DECODE(SIGN(ROWNUM-10),-1,&#039;&#039;,MOD(TRUNC(ROWNUM/10),10))) &#124;&#124;
      TO_CHAR(DECODE(SIGN(ROWNUM-100),-1,&#039;&#039;,MOD(TRUNC(ROWNUM/100),10))) &#124;&#124;
      TO_CHAR(DECODE(SIGN(ROWNUM-1000),-1,&#039;&#039;,MOD(TRUNC(ROWNUM/1000),10))) &#124;&#124;
      TO_CHAR(DECODE(SIGN(ROWNUM-10000),-1,&#039;&#039;,MOD(TRUNC(ROWNUM/10000),10))) &#124;&#124;
      TO_CHAR(DECODE(SIGN(ROWNUM-100000),-1,&#039;&#039;,MOD(TRUNC(ROWNUM/100000),10))) &#124;&#124;
      TO_CHAR(DECODE(SIGN(ROWNUM-1000000),-1,&#039;&#039;,MOD(TRUNC(ROWNUM/1000000),10))) &#124;&#124;
      TO_CHAR(DECODE(SIGN(ROWNUM-10000000),-1,&#039;&#039;,MOD(TRUNC(ROWNUM/10000000),10))) &#124;&#124;
      TO_CHAR(DECODE(SIGN(ROWNUM-100000000),-1,&#039;&#039;,MOD(TRUNC(ROWNUM/100000000),10)))) RN
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=1000000)
WHERE
  N &lt;&gt; RN
  AND N/10 &lt;&gt; TRUNC(N/10)
  AND N/RN=TRUNC(N/RN)
  AND N &gt; RN;
&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>Another method &#8211; use mathematics to reverse the digits in the numbers &#8211; the DECODE and SIGN conbination make certain that we do not accidentally pad additional zeros at the end of the reversed number:</p>
<pre>
SELECT
  ROWNUM N,
  TO_NUMBER(
    TO_CHAR(MOD(ROWNUM,10)) ||
    TO_CHAR(DECODE(SIGN(ROWNUM-10),-1,'',MOD(TRUNC(ROWNUM/10),10))) ||
    TO_CHAR(DECODE(SIGN(ROWNUM-100),-1,'',MOD(TRUNC(ROWNUM/100),10))) ||
    TO_CHAR(DECODE(SIGN(ROWNUM-1000),-1,'',MOD(TRUNC(ROWNUM/1000),10))) ||
    TO_CHAR(DECODE(SIGN(ROWNUM-10000),-1,'',MOD(TRUNC(ROWNUM/10000),10))) ||
    TO_CHAR(DECODE(SIGN(ROWNUM-100000),-1,'',MOD(TRUNC(ROWNUM/100000),10))) ||
    TO_CHAR(DECODE(SIGN(ROWNUM-1000000),-1,'',MOD(TRUNC(ROWNUM/1000000),10))) ||
    TO_CHAR(DECODE(SIGN(ROWNUM-10000000),-1,'',MOD(TRUNC(ROWNUM/10000000),10))) ||
    TO_CHAR(DECODE(SIGN(ROWNUM-100000000),-1,'',MOD(TRUNC(ROWNUM/100000000),10)))) RN
FROM
  DUAL
CONNECT BY
  LEVEL&lt;=1000;
 
---------- ---------
         1         1
         2         2
         3         3
         4         4
         5         5
         6         6
         7         7
         8         8
         9         9
        10         1
        11        11
        12        21
        13        31
...
       996       699
       997       799
       998       899
       999       999
      1000         1
</pre>
<p>Then slide the above into an inline view to perform the tests:</p>
<pre>
SELECT
  N,
  RN,
  N/RN DIV
FROM
  (SELECT
    ROWNUM N,
    TO_NUMBER(
      TO_CHAR(MOD(ROWNUM,10)) ||
      TO_CHAR(DECODE(SIGN(ROWNUM-10),-1,'',MOD(TRUNC(ROWNUM/10),10))) ||
      TO_CHAR(DECODE(SIGN(ROWNUM-100),-1,'',MOD(TRUNC(ROWNUM/100),10))) ||
      TO_CHAR(DECODE(SIGN(ROWNUM-1000),-1,'',MOD(TRUNC(ROWNUM/1000),10))) ||
      TO_CHAR(DECODE(SIGN(ROWNUM-10000),-1,'',MOD(TRUNC(ROWNUM/10000),10))) ||
      TO_CHAR(DECODE(SIGN(ROWNUM-100000),-1,'',MOD(TRUNC(ROWNUM/100000),10))) ||
      TO_CHAR(DECODE(SIGN(ROWNUM-1000000),-1,'',MOD(TRUNC(ROWNUM/1000000),10))) ||
      TO_CHAR(DECODE(SIGN(ROWNUM-10000000),-1,'',MOD(TRUNC(ROWNUM/10000000),10))) ||
      TO_CHAR(DECODE(SIGN(ROWNUM-100000000),-1,'',MOD(TRUNC(ROWNUM/100000000),10)))) RN
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=1000000)
WHERE
  N &lt;&gt; RN
  AND N/10 &lt;&gt; TRUNC(N/10)
  AND N/RN=TRUNC(N/RN)
  AND N &gt; RN;
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://hoopercharles.wordpress.com/2011/07/31/the-new-order-oracle-coding-challenge-1/#comment-3729</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Mon, 01 Aug 2011 15:48:34 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5210#comment-3729</guid>
		<description><![CDATA[If you did not know about the undocumented REVERSE function and were running a version of Oracle Database prior to 11.2.0.1, how might you solve this sort of problem?

If you you know that the largest number will have 10 digits, you could do something like the following:
&lt;pre&gt;
SELECT
  N,
  RN
FROM
  (SELECT
    N,
    TO_NUMBER(SUBSTR(VN,10,1)&#124;&#124;SUBSTR(VN,9,1)&#124;&#124;SUBSTR(VN,8,1)&#124;&#124;SUBSTR(VN,7,1)&#124;&#124;SUBSTR(VN,6,1)&#124;&#124;SUBSTR(VN,5,1)&#124;&#124;SUBSTR(VN,4,1)&#124;&#124;SUBSTR(VN,3,1)&#124;&#124;SUBSTR(VN,2,1)&#124;&#124;SUBSTR(VN,1,1)) RN
  FROM
    (SELECT
      ROWNUM N,
      TO_CHAR(ROWNUM) VN,
      LENGTH(TO_CHAR(ROWNUM)) LN
    FROM
      DUAL
    CONNECT BY
      LEVEL&lt;=1000000) N
  WHERE
    MOD(N,10) != 0)
WHERE
  N != RN
  AND MOD(N, RN) = 0;
&lt;/pre&gt;

The above approach is probably a bit slow.

Instead, you might build a reverse number function:
&lt;pre&gt;
CREATE OR REPLACE FUNCTION REVERSE_NUMBER (LNG_NUMBER IN NUMBER) RETURN NUMBER
IS
  STR_NUMBER VARCHAR2(15);
  STR_RNUMBER VARCHAR2(15);
  LNG_RNUMBER NUMBER;
  INT_LENGTH NUMBER;
BEGIN
  STR_NUMBER := TRIM(TO_CHAR(LNG_NUMBER));
  INT_LENGTH := LENGTH(STR_NUMBER);
  FOR I IN 1 .. INT_LENGTH LOOP
    STR_RNUMBER := STR_RNUMBER &#124;&#124; SUBSTR(STR_NUMBER, INT_LENGTH - I + 1, 1);
  END LOOP;
  LNG_RNUMBER := TO_NUMBER(STR_RNUMBER);
  
  RETURN LNG_RNUMBER;
END REVERSE_NUMBER;
/
&lt;/pre&gt;

&lt;pre&gt;
SELECT
  N,
  RN
FROM
  (SELECT
    ROWNUM N,
    REVERSE_NUMBER(ROWNUM) RN
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=1000000)
WHERE
  N/10 != TRUNC(N/10)
  AND N/RN = TRUNC(N/RN)
  AND N != RN;
&lt;/pre&gt;

Any other solutions?]]></description>
		<content:encoded><![CDATA[<p>If you did not know about the undocumented REVERSE function and were running a version of Oracle Database prior to 11.2.0.1, how might you solve this sort of problem?</p>
<p>If you you know that the largest number will have 10 digits, you could do something like the following:</p>
<pre>
SELECT
  N,
  RN
FROM
  (SELECT
    N,
    TO_NUMBER(SUBSTR(VN,10,1)||SUBSTR(VN,9,1)||SUBSTR(VN,8,1)||SUBSTR(VN,7,1)||SUBSTR(VN,6,1)||SUBSTR(VN,5,1)||SUBSTR(VN,4,1)||SUBSTR(VN,3,1)||SUBSTR(VN,2,1)||SUBSTR(VN,1,1)) RN
  FROM
    (SELECT
      ROWNUM N,
      TO_CHAR(ROWNUM) VN,
      LENGTH(TO_CHAR(ROWNUM)) LN
    FROM
      DUAL
    CONNECT BY
      LEVEL&lt;=1000000) N
  WHERE
    MOD(N,10) != 0)
WHERE
  N != RN
  AND MOD(N, RN) = 0;
</pre>
<p>The above approach is probably a bit slow.</p>
<p>Instead, you might build a reverse number function:</p>
<pre>
CREATE OR REPLACE FUNCTION REVERSE_NUMBER (LNG_NUMBER IN NUMBER) RETURN NUMBER
IS
  STR_NUMBER VARCHAR2(15);
  STR_RNUMBER VARCHAR2(15);
  LNG_RNUMBER NUMBER;
  INT_LENGTH NUMBER;
BEGIN
  STR_NUMBER := TRIM(TO_CHAR(LNG_NUMBER));
  INT_LENGTH := LENGTH(STR_NUMBER);
  FOR I IN 1 .. INT_LENGTH LOOP
    STR_RNUMBER := STR_RNUMBER || SUBSTR(STR_NUMBER, INT_LENGTH - I + 1, 1);
  END LOOP;
  LNG_RNUMBER := TO_NUMBER(STR_RNUMBER);
  
  RETURN LNG_RNUMBER;
END REVERSE_NUMBER;
/
</pre>
<pre>
SELECT
  N,
  RN
FROM
  (SELECT
    ROWNUM N,
    REVERSE_NUMBER(ROWNUM) RN
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=1000000)
WHERE
  N/10 != TRUNC(N/10)
  AND N/RN = TRUNC(N/RN)
  AND N != RN;
</pre>
<p>Any other solutions?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://hoopercharles.wordpress.com/2011/07/31/the-new-order-oracle-coding-challenge-1/#comment-3728</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Mon, 01 Aug 2011 14:33:06 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5210#comment-3728</guid>
		<description><![CDATA[I forgot to mention that it is possible to work around the &quot;not enough memory&quot; error when using CONNECT BY through the use of an intentional Cartesian join.  As demonstrated below, checking all numbers up to 10,000,000:
&lt;pre&gt;
SELECT
  N,
  RN
FROM
  (SELECT
    ROWNUM N,
    TO_NUMBER(REVERSE(TO_CHAR(ROWNUM))) RN
  FROM
    (SELECT
      ROWNUM N
    FROM
      DUAL
    CONNECT BY
      LEVEL&lt;=100000) V1,
    (SELECT
      ROWNUM N
    FROM
      DUAL
    CONNECT BY
      LEVEL&lt;=100) V2)
WHERE
  MOD(N,RN)=0
  AND N &lt;&gt; RN
  AND SUBSTR(TO_CHAR(N),-1)&lt;&gt;&#039;0&#039;;
 
         N         RN
---------- ----------
      8712       2178
      9801       1089
     87912      21978
     98901      10989
    879912     219978
    989901     109989
   8799912    2199978
   9899901    1099989
&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>I forgot to mention that it is possible to work around the &#8220;not enough memory&#8221; error when using CONNECT BY through the use of an intentional Cartesian join.  As demonstrated below, checking all numbers up to 10,000,000:</p>
<pre>
SELECT
  N,
  RN
FROM
  (SELECT
    ROWNUM N,
    TO_NUMBER(REVERSE(TO_CHAR(ROWNUM))) RN
  FROM
    (SELECT
      ROWNUM N
    FROM
      DUAL
    CONNECT BY
      LEVEL&lt;=100000) V1,
    (SELECT
      ROWNUM N
    FROM
      DUAL
    CONNECT BY
      LEVEL&lt;=100) V2)
WHERE
  MOD(N,RN)=0
  AND N &lt;&gt; RN
  AND SUBSTR(TO_CHAR(N),-1)&lt;&gt;'0';
 
         N         RN
---------- ----------
      8712       2178
      9801       1089
     87912      21978
     98901      10989
    879912     219978
    989901     109989
   8799912    2199978
   9899901    1099989
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://hoopercharles.wordpress.com/2011/07/31/the-new-order-oracle-coding-challenge-1/#comment-3727</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Mon, 01 Aug 2011 14:10:09 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5210#comment-3727</guid>
		<description><![CDATA[Chris,

Good idea to use the LISTAGG function - the concept behind what you did will be necessary for part 2 of the blog article series.

I have 3 other solutions to this particular problem waiting to be publish, in the hope that someone else will come up with a similar (and likely better) solution - there will certainly be variances between my approach and the one proposed by readers of this blog.  For example, the following is the example that I put together using the LISTAGG function:

Building a solution to handle up to a 10 digit number.  The idea in this case is to convert the number to a string (VARCHAR), join the number to a view that counts from 1 up to the number of characters in the string version of the number, and use the SUBSTR function to pull out the digits from the right to the left:
&lt;pre&gt;
SELECT
  N.N,
  C.C,
  SUBSTR(N.VN, N.LN - (C.C - 1),1) RN
FROM
  (SELECT
    ROWNUM N,
    TO_CHAR(ROWNUM) VN,
    LENGTH(TO_CHAR(ROWNUM)) LN
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=100) N,
  (SELECT
    ROWNUM C
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=10) C
WHERE
  C.C&lt;=N.LN;
 
   N  C R
---- -- -
   1  1 1
   2  1 2
   3  1 3
   4  1 4
   5  1 5
   6  1 6
   7  1 7
   8  1 8
   9  1 9
  10  1 0
  10  2 1
  11  1 1
  11  2 1
  12  1 2
  12  2 1
...
  99  1 9
  99  2 9
 100  1 0
 100  2 0
 100  3 1
&lt;/pre&gt;

Next, we use the LISTAGG function that was introduced in 11.2.0.1 to recombine the reverse ordered digits back into a single row:
&lt;pre&gt;
SELECT
  N.N,
  TO_NUMBER(LISTAGG(SUBSTR(N.VN, N.LN - (C.C - 1),1), &#039;&#039;) WITHIN GROUP (ORDER BY C.C)) RN
FROM
  (SELECT
    ROWNUM N,
    TO_CHAR(ROWNUM) VN,
    LENGTH(TO_CHAR(ROWNUM)) LN
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=1000) N,
  (SELECT
    ROWNUM C
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=10) C
WHERE
  C.C&lt;=N.LN
GROUP BY
  N.N;
 
    N    RN
----- -----
    1     1
    2     2
    3     3
    4     4
    5     5
    6     6
    7     7
    8     8
    9     9
   10     1
   11    11
   12    21
...
  993   399
  994   499
  995   599
  996   699
  997   799
  998   899
  999   999
 1000     1
&lt;/pre&gt;

The final step performs the specified checks:
&lt;pre&gt;
SELECT
  N,
  RN,
  N/RN RESULT
FROM
  (SELECT
    N.N,
    TO_NUMBER(LISTAGG(SUBSTR(N.VN, N.LN - (C.C - 1),1), &#039;&#039;) WITHIN GROUP (ORDER BY C.C)) RN
  FROM
    (SELECT
      ROWNUM N,
      TO_CHAR(ROWNUM) VN,
      LENGTH(TO_CHAR(ROWNUM)) LN
    FROM
      DUAL
    CONNECT BY
      LEVEL&lt;=1000000) N,
    (SELECT
      ROWNUM C
    FROM
      DUAL
    CONNECT BY
      LEVEL&lt;=10) C
  WHERE
    C.C&lt;=N.LN
    AND N.N/10 != TRUNC(N.N/10)
  GROUP BY
    N.N)
WHERE
  N/RN = TRUNC(N/RN)
  AND N != RN;
 
      N      RN     RESULT
------- ------- ----------
   8712    2178          4
   9801    1089          9
  87912   21978          4
  98901   10989          9
 879912  219978          4
 989901  109989          9
&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>Chris,</p>
<p>Good idea to use the LISTAGG function &#8211; the concept behind what you did will be necessary for part 2 of the blog article series.</p>
<p>I have 3 other solutions to this particular problem waiting to be publish, in the hope that someone else will come up with a similar (and likely better) solution &#8211; there will certainly be variances between my approach and the one proposed by readers of this blog.  For example, the following is the example that I put together using the LISTAGG function:</p>
<p>Building a solution to handle up to a 10 digit number.  The idea in this case is to convert the number to a string (VARCHAR), join the number to a view that counts from 1 up to the number of characters in the string version of the number, and use the SUBSTR function to pull out the digits from the right to the left:</p>
<pre>
SELECT
  N.N,
  C.C,
  SUBSTR(N.VN, N.LN - (C.C - 1),1) RN
FROM
  (SELECT
    ROWNUM N,
    TO_CHAR(ROWNUM) VN,
    LENGTH(TO_CHAR(ROWNUM)) LN
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=100) N,
  (SELECT
    ROWNUM C
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=10) C
WHERE
  C.C&lt;=N.LN;
 
   N  C R
---- -- -
   1  1 1
   2  1 2
   3  1 3
   4  1 4
   5  1 5
   6  1 6
   7  1 7
   8  1 8
   9  1 9
  10  1 0
  10  2 1
  11  1 1
  11  2 1
  12  1 2
  12  2 1
...
  99  1 9
  99  2 9
 100  1 0
 100  2 0
 100  3 1
</pre>
<p>Next, we use the LISTAGG function that was introduced in 11.2.0.1 to recombine the reverse ordered digits back into a single row:</p>
<pre>
SELECT
  N.N,
  TO_NUMBER(LISTAGG(SUBSTR(N.VN, N.LN - (C.C - 1),1), '') WITHIN GROUP (ORDER BY C.C)) RN
FROM
  (SELECT
    ROWNUM N,
    TO_CHAR(ROWNUM) VN,
    LENGTH(TO_CHAR(ROWNUM)) LN
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=1000) N,
  (SELECT
    ROWNUM C
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=10) C
WHERE
  C.C&lt;=N.LN
GROUP BY
  N.N;
 
    N    RN
----- -----
    1     1
    2     2
    3     3
    4     4
    5     5
    6     6
    7     7
    8     8
    9     9
   10     1
   11    11
   12    21
...
  993   399
  994   499
  995   599
  996   699
  997   799
  998   899
  999   999
 1000     1
</pre>
<p>The final step performs the specified checks:</p>
<pre>
SELECT
  N,
  RN,
  N/RN RESULT
FROM
  (SELECT
    N.N,
    TO_NUMBER(LISTAGG(SUBSTR(N.VN, N.LN - (C.C - 1),1), '') WITHIN GROUP (ORDER BY C.C)) RN
  FROM
    (SELECT
      ROWNUM N,
      TO_CHAR(ROWNUM) VN,
      LENGTH(TO_CHAR(ROWNUM)) LN
    FROM
      DUAL
    CONNECT BY
      LEVEL&lt;=1000000) N,
    (SELECT
      ROWNUM C
    FROM
      DUAL
    CONNECT BY
      LEVEL&lt;=10) C
  WHERE
    C.C&lt;=N.LN
    AND N.N/10 != TRUNC(N.N/10)
  GROUP BY
    N.N)
WHERE
  N/RN = TRUNC(N/RN)
  AND N != RN;
 
      N      RN     RESULT
------- ------- ----------
   8712    2178          4
   9801    1089          9
  87912   21978          4
  98901   10989          9
 879912  219978          4
 989901  109989          9
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Saxon</title>
		<link>http://hoopercharles.wordpress.com/2011/07/31/the-new-order-oracle-coding-challenge-1/#comment-3725</link>
		<dc:creator><![CDATA[Chris Saxon]]></dc:creator>
		<pubDate>Mon, 01 Aug 2011 12:27:26 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5210#comment-3725</guid>
		<description><![CDATA[Going back to the inefficient ways to do this, how about the following (requires 11gR2):

&lt;pre&gt;
select n, rev, n/rev
from (
      select listagg(s, &#039;&#039;) within group (order by l) rev, n
      from (
            select substr(to_char(d.n), -l.n, 1) s, d.n n, l.n l
            from (select rownum n, length(rownum) len
                  from   dual d
                  connect by level &lt;= :value) d,
                 (select rownum n
                  from   dual
                  connect by level &lt;= length(:value)) l
            where l.n &lt;= d.len
            and   mod(d.n, 10) &lt;&gt; 0
      )
      group  by n
)
where floor(n/rev) = ceil(n/rev)
and   n &lt;&gt; rev;
&lt;/pre&gt;

This makes a custom reverse function by generating a row for each digit in a number. Work backwards through the digits in the number (using negative numbers in the substr). Then combine back together using listagg. 

You could use a positive number in the substr and order descending in the listagg grouping clause as well. 

I also hit the &quot;not enough memory&quot; error when trying this with 10,000,000 rows.]]></description>
		<content:encoded><![CDATA[<p>Going back to the inefficient ways to do this, how about the following (requires 11gR2):</p>
<pre>
select n, rev, n/rev
from (
      select listagg(s, '') within group (order by l) rev, n
      from (
            select substr(to_char(d.n), -l.n, 1) s, d.n n, l.n l
            from (select rownum n, length(rownum) len
                  from   dual d
                  connect by level &lt;= :value) d,
                 (select rownum n
                  from   dual
                  connect by level &lt;= length(:value)) l
            where l.n &lt;= d.len
            and   mod(d.n, 10) &lt;&gt; 0
      )
      group  by n
)
where floor(n/rev) = ceil(n/rev)
and   n &lt;&gt; rev;
</pre>
<p>This makes a custom reverse function by generating a row for each digit in a number. Work backwards through the digits in the number (using negative numbers in the substr). Then combine back together using listagg. </p>
<p>You could use a positive number in the substr and order descending in the listagg grouping clause as well. </p>
<p>I also hit the &#8220;not enough memory&#8221; error when trying this with 10,000,000 rows.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Hooper</title>
		<link>http://hoopercharles.wordpress.com/2011/07/31/the-new-order-oracle-coding-challenge-1/#comment-3724</link>
		<dc:creator><![CDATA[Charles Hooper]]></dc:creator>
		<pubDate>Sun, 31 Jul 2011 21:36:15 +0000</pubDate>
		<guid isPermaLink="false">http://hoopercharles.wordpress.com/?p=5210#comment-3724</guid>
		<description><![CDATA[Gary,

That is an interesting observation - I did not see the pattern until you pointed it out.

&lt;pre&gt;
SELECT
  N,
  RN,
  N/RN DIV
FROM
  (SELECT
    TO_NUMBER(RPAD(&#039;98&#039;,2+ROWNUM-1,&#039;9&#039;)&#124;&#124;&#039;01&#039;) N,
    TO_NUMBER(REVERSE(RPAD(&#039;98&#039;,2+ROWNUM-1,&#039;9&#039;)&#124;&#124;&#039;01&#039;)) RN
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=16);
  
                   N                   RN        DIV
-------------------- -------------------- ----------
                9801                 1089          9
               98901                10989          9
              989901               109989          9
             9899901              1099989          9
            98999901             10999989          9
           989999901            109999989          9
          9899999901           1099999989          9
         98999999901          10999999989          9
        989999999901         109999999989          9
       9899999999901        1099999999989          9
      98999999999901       10999999999989          9
     989999999999901      109999999999989          9
    9899999999999901     1099999999999989          9
   98999999999999901    10999999999999989          9
  989999999999999901   109999999999999989          9
 9899999999999999901  1099999999999999989          9
 
16 rows selected.
&lt;/pre&gt;

&lt;pre&gt;
SELECT
  N,
  RN,
  N/RN DIV
FROM
  (SELECT
    TO_NUMBER(RPAD(&#039;87&#039;,2+ROWNUM-1,&#039;9&#039;)&#124;&#124;&#039;12&#039;) N,
    TO_NUMBER(REVERSE(RPAD(&#039;87&#039;,2+ROWNUM-1,&#039;9&#039;)&#124;&#124;&#039;12&#039;)) RN
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=16);
  
                   N                   RN        DIV
-------------------- -------------------- ----------
                8712                 2178          4
               87912                21978          4
              879912               219978          4
             8799912              2199978          4
            87999912             21999978          4
           879999912            219999978          4
          8799999912           2199999978          4
         87999999912          21999999978          4
        879999999912         219999999978          4
       8799999999912        2199999999978          4
      87999999999912       21999999999978          4
     879999999999912      219999999999978          4
    8799999999999912     2199999999999978          4
   87999999999999912    21999999999999978          4
  879999999999999912   219999999999999978          4
 8799999999999999912  2199999999999999978          4
 
16 rows selected.
&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>Gary,</p>
<p>That is an interesting observation &#8211; I did not see the pattern until you pointed it out.</p>
<pre>
SELECT
  N,
  RN,
  N/RN DIV
FROM
  (SELECT
    TO_NUMBER(RPAD('98',2+ROWNUM-1,'9')||'01') N,
    TO_NUMBER(REVERSE(RPAD('98',2+ROWNUM-1,'9')||'01')) RN
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=16);
  
                   N                   RN        DIV
-------------------- -------------------- ----------
                9801                 1089          9
               98901                10989          9
              989901               109989          9
             9899901              1099989          9
            98999901             10999989          9
           989999901            109999989          9
          9899999901           1099999989          9
         98999999901          10999999989          9
        989999999901         109999999989          9
       9899999999901        1099999999989          9
      98999999999901       10999999999989          9
     989999999999901      109999999999989          9
    9899999999999901     1099999999999989          9
   98999999999999901    10999999999999989          9
  989999999999999901   109999999999999989          9
 9899999999999999901  1099999999999999989          9
 
16 rows selected.
</pre>
<pre>
SELECT
  N,
  RN,
  N/RN DIV
FROM
  (SELECT
    TO_NUMBER(RPAD('87',2+ROWNUM-1,'9')||'12') N,
    TO_NUMBER(REVERSE(RPAD('87',2+ROWNUM-1,'9')||'12')) RN
  FROM
    DUAL
  CONNECT BY
    LEVEL&lt;=16);
  
                   N                   RN        DIV
-------------------- -------------------- ----------
                8712                 2178          4
               87912                21978          4
              879912               219978          4
             8799912              2199978          4
            87999912             21999978          4
           879999912            219999978          4
          8799999912           2199999978          4
         87999999912          21999999978          4
        879999999912         219999999978          4
       8799999999912        2199999999978          4
      87999999999912       21999999999978          4
     879999999999912      219999999999978          4
    8799999999999912     2199999999999978          4
   87999999999999912    21999999999999978          4
  879999999999999912   219999999999999978          4
 8799999999999999912  2199999999999999978          4
 
16 rows selected.
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>
