| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> comp.databases.theory -> Re: Puzzle: What should this query return?
This gets weird in Standard SQL.
CREATE TABLE Foobar (I INTEGER NOT NULL); INSERT INTO Foobar VALUES (1);
SELECT * FROM Foobar; -- returns 1
SELECT * FROM Foobar WHERE 1=0; -- returns empty set
SELECT COUNT(*) FROM Foobar WHERE 1=0; -- returns 0
CASE expressions are evaluated in the order they are written:
SELECT CASE WHEN 1 = 1
THEN 12
ELSE COUNT(*) END AS x
Ocelot reasoning seems to be that we have an ambigous syntax and we just blow up.
Another line of reasoning is we can parse the SELECT clause and reduce it to:
SELECT 12 FROM Foobar WHERE 1 = 0; --returns empty.
Or if we had
SELECT CASE WHEN 1 = 0
THEN 12
ELSE COUNT(*)+1 END AS x
SELECT COUNT(*) + 1 FROM Foobar WHERE 1 = 0; --returns 1
I think we might have a problem here .... Received on Sat Jun 29 2002 - 10:34:23 CDT
![]() |
![]() |