random technical thoughts from the Nominet technical team

Clever SQL trick that could come back to bite you

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
Posted by chris on Jan 5th, 2007

I recently moved some test code written in PL/SQL from one database (Solaris, Oracle 10.1, US7ASCII) to another (Linux, Oracle 10.2, UTF8). This revealed a SQL trick that doesn’t work quite as expected on the new platform, almost certainly due to the change in Oracle version. The code in question is:

SELECT 1
FROM DUAL
CONNECT BY ROWNUM <= 7

This returns 8 rows on the first database and 7 on the second. I suspect that this is due to a change in the point that ROWNUM is incremented in the processing of the query. As I said, this was only in test code, but I guess that the lesson here is that if you rely on unsupported SQL tricks then don’t be surprised if their behaviour changes.

One Response

  1. David Phillips Says:

    Your blog ate the rest of my query. Let’s try again:

    SELECT 1 FROM DUAL CONNECT BY LEVEL *LTE* 7;

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Recent Posts

Highest Rated

Categories

Archives

Meta: