Oracle Question and Answer

  • Do you have a solution to a problem? Do you have an unanswered question? Login and share it with the Oracle community. More...

Oracle News

Entries RSS feed

Comments RSS feed

How to solve the Length 9 puzzle in SQL

October 23rd, 2007 By Frank Zhou

The following is an interesting puzzle posted on Usenet rec.puzzles archive:

Is it possible to make a number and its square, using the digits from 1 through 9 exactly once?

———————-SQL solution————————

SELECT   num, square
(SELECT  LEVEL as num, power(LEVEL, 2) square  FROM dual
  WHERE  translate( '123456789', 'X'||power(LEVEL,2)||LEVEL,'X') IS  NULL
 CONNECT BY to_number(power(LEVEL, 2)||LEVEL) <= 987654321

       NUM     SQUARE
---------- ----------
       567     321489
       854     729316

Elapsed: 00:00:00.31

Leave a Reply

You must be logged in to post a comment.

RSS feed for comments on this question