Home » SQL & PL/SQL » SQL & PL/SQL » "Where 1=2 " . How it works internally?
"Where 1=2 " . How it works internally? [message #611938] Thu, 10 April 2014 05:22 Go to next message
Bikash.p
Messages: 11
Registered: April 2014
Location: Banglore
Junior Member
If condition is true then it will create the table with all rows ,If not then it will create only the schema. This is reason ya any thing behind this?

create table aa as select * from student2 where 1=2;
select * from aa;

no rows selected

create table aaa as select * from student2 where 1=1;
select * from aaa;

6 rows selected
Re: "Where 1=2 " . How it works internally? [message #611939 is a reply to message #611938] Thu, 10 April 2014 05:25 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
That's the way oracle decided it would work. The create table always works, the only question is how many rows get inserted.
Re: "Where 1=2 " . How it works internally? [message #611940 is a reply to message #611938] Thu, 10 April 2014 05:35 Go to previous messageGo to next message
Michel Cadot
Messages: 68647
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

CTAS first creates the table with the columns defined by the selected expressions. There is no need to fetch the result of the query to get the columns definition.
After that Oracle fills the new table fetching the result of the query.

Re: "Where 1=2 " . How it works internally? [message #611944 is a reply to message #611939] Thu, 10 April 2014 05:46 Go to previous message
Bikash.p
Messages: 11
Registered: April 2014
Location: Banglore
Junior Member
Thanks Everybody.
Previous Topic: How to return 0 when Inline View is returning NULL
Next Topic: How to fetch last N records from the table?
Goto Forum:
  


Current Time: Fri Apr 26 17:25:37 CDT 2024