Transfer: https://www.linuxidc.com/Linux/2010-05/26202.htm
Myt create tables and insert data, as follows:
create table myt(name varchar2,create_time date)
insert into myt values('john',to_date(sysdate,'DD-MON-YY'));
insert into myt values('tom',to_date(sysdate,'DD-MON-YY'));
insert into myt values('lili',to_date(sysdate,'DD-MON-YY'));
In sql * plus shown below:
SQL> select * from myt;
NAME CREATE_TIME
---------- -----------
john 2010-5-19
tom 2010-5-19
lili 2010-5-19
SQL> select 1 from myt;
1
----------
1
1
1
The SQL> SELECT MYT from 0;
0
----------
0
0
0
can be seen from the above results, select constant fromtable returns the corresponding constant value for all rows (specific applications see below),
And select * from table corresponding to all columns of all rows are returned.
select 1 exists in the common clause, meet the conditions detected record exists.
The select * from T1 where exists (select 1 from T2 where T1.a = T2.a);
small amount data T2 T1 data is very large, T1 << T2, the high-1) query efficiency.
"Select 1" where "1" is actually irrelevant, replaced by "*" is also no problem, www.linuxidc.com only care about data in brackets can not find out whether such a record exists, if there is where conditions are met.
The following example:
SQL> select 1/0 from dual;
select 1/0 from dual
ORA-01476: 除数为 0
SQL> select * from myt where exists(select 1/0 from dual);
NAME CREATE_TIME
---------- -----------
john 2010-5-19
tom 2010-5-19
lili 2010-5-19
He did not return an error, instructions, and did not let the select statement involved in the calculation.
Written in the select * clause exists does not return all the columns in the table, just to detect qualifying record exists.