tags:

views:

242

answers:

4

Why doesn't it work?

SELECT a.*
FROM dual a
     JOIN (SELECT * FROM dual WHERE 1=1) b
     ON (1=1);

I get "ORA-00900: invalid SQL statement". Is there a way to use WHERE clause inside the subquery?

Edit: Version 9.2

SELECT *
FROM v$version

Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production

The following executes just fine:

SELECT a.*
FROM dual a
     JOIN (SELECT * FROM dual /*WHERE 1=1*/) b
     ON (1=1)
+1  A: 

What version are you using?

The exact same SQL works fine for me (Oracle Database 10g Express Edition Release 10.2.0.1.0).

Thilo
A: 

It looks correct to me and I am able to execute it in 10g, but it fails with 8i, which version of Oracle are you using?

pedromarce
+1  A: 

Oracle below 9i does not support ANSI join syntax.

Use this if you're on 8i and below:

SELECT  a.*
FROM    dual a,
        (
        SELECT  *
        FROM    dual
        WHERE   1 = 1
        ) b
WHERE   1 = 1
Quassnoi
I've edited the question to show that my version (9.2) supports ANSI joins but not this one particular.
jva
+1  A: 

It works for me on 9.2 (32 bit version is the only difference):

SQL> SELECT a.*
  2  FROM dual a
  3       JOIN (SELECT * FROM dual WHERE 1=1) b
  4       ON (1=1);

D
-
X

SQL> quit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production
With the OLAP and Oracle Data Mining options
JServer Release 9.2.0.8.0 - Production
DCookie
This is what solved my problem. Turns out it was a bug in SQL Navigator. Works fine in SQL*Plus.
jva