±È½ÏOracle SQLÖеÄIN & EXISTS
ÔÚOracle SQLÖÐÈ¡Êý¾ÝʱÓÐʱҪÓõ½in ºÍ exists ÄÇôËûÃÇÓÐʲôÇø±ðÄØ£¿
1 ÐÔÄÜÉϵıȽÏ
±ÈÈçSelect * from T1 where x in ( select y from T2 )
Ö´ÐеĹý³ÌÏ൱ÓÚ:
select *
from t1, ( select distinct y from t2 ) t2
where t1.x = t2.y;
숦﵀
select * from t1 where exists ( select null from t2 where y = x )
Ö´ÐеĹý³ÌÏ൱ÓÚ:
for x in ( select * from t1 )
loop
if ( exists ( select null from t2 where y = x.x )
then
OUTPUT THE RECORD
end if
end loop
±í T1 ²»¿É±ÜÃâµÄÒª±»ÍêȫɨÃèÒ»±é
·Ö±ðÊÊÓÃÔÚʲôÇé¿ö?
ÒÔ×Ó²éѯ ( select y from T2 )Ϊ¿¼ÂÇ·½Ïò
Èç¹û×Ó²éѯµÄ½á¹û¼¯ºÜ´óÐèÒªÏûºÄºÜ¶àʱ¼ä£¬µ«ÊÇT1±È½ÏСִÐÐ( select null from t2 where y = x.x )·Ç³£¿ì£¬ÄÇôexists¾Í±È½ÏÊʺÏÓÃÔÚÕâÀï
Ïà¶ÔÓ¦µÃ×Ó²éѯµÄ½á¹û¼¯±È½ÏСµÄʱºò¾ÍÓ¦¸ÃʹÓÃin.
2 º¬ÒåÉϵıȽÏ
ÔÚ±ê×¼µÄscott/tigerÓû§ÏÂ
EMPNO
ENAME
JOB
MGR
HIREDATE
SAL
COMM
DEPTNO
1
7499
ALLEN
SALESMAN
7698
1981/02/20
1600.00
300.00
30
2
7521
WARD
SALESMAN
7698
1981/02/22
1250.00
500.00
30
3
7566
JONES
MANAGER
7839
1981/04/02
2975.00
20
4
7654
MARTIN
SALESMAN
7698
1981/09/28
1250.00
1400.00
30
5
7698
BLAKE
MANAGER
7839
1981/05/01
2850.00
30
6
7782
CLARK
MANAGER
7839
1981/06/09
2450.00
10
7
7788
SCOTT
ANALYST
7566
1987/04/19
3000.00
20
8
7839
KING
PRESIDENT
¡¡
1981/11/17
5000.00
10
9
7844
TURNER
SALESMAN
7698
1981/09/08
1500.00
0.00
30
10
7876
ADAMS
CLERK
7788
1987/05/23
1100.00
20
11
7900
JAMES
CLERK
7698
1981/12/03
950.00
30
12
7902
FORD
ANALYST
7566
1981/12/03
3000.00
20
13
7934
MILLER
CLERK
7782
1982/01/23
1300.00
¡¡
10
Ö´ÐÐ
SQL> select count(*) from emp where empno not in ( select mgr from emp );
COUNT(
Ïà¹ØÎĵµ£º
OracleÍⲿÉí·ÝÈÏÖ¤Ñо¿
ÃÜÂëÎļþÈÏÖ¤ ²Ù×÷ϵͳÈÏÖ¤ remote_login_passwordfile SQLNET.AUTHENTICATION_SERVICES &nb ......
ͨ¹ý select * from table whereid=16701 for update ËøסһÕűí
ͨ¹ýÒÔÏÂÓï¾ä¿É²éѯ³ö±»ËøסµÄ¶ÔÏó
SELECT OBJECT_ID,
SESSION_ID,
SERIAL#,
ORACLE_USERNAME,
&nb ......
µ¼Èë IMP
Oracle µÄµ¼ÈëʵÓóÌÐò (Import utility) ÔÊÐí´ÓÊý¾Ý¿âÌáÈ¡Êý¾Ý£¬²¢ÇÒ½«Êý¾ÝдÈë²Ù×÷ϵͳÎļþ¡£ imp ʹÓõĻù±¾¸ñʽ£º imp[username[/password[@service]]] £¬ÒÔÏÂÀý¾Ù imp ³£ÓÃÓ÷¨¡£
1. »ñÈ¡°ïÖú
imp help=y
2. µ¼ÈëÒ»¸öÍêÕûÊý¾Ý¿â
imp system/manager file=bible_db log=dibl ......
ÒòΪ¹«Ë¾µÄÕÆÉϳÇÊÐϵͳÔÚ¶à¸öµØÊÆͬʱÉÏÏߣ¬¶øΪÁËÈÃÿ¸ö³ÇÊеÄ3G¿ìѶ¾ßÓеØÊÆÌØÉ«ÐÔ£¬Ã¿¸öµØÊÆÓÐ×Ô¼ºµ¥¶ÀµÄÊý¾Ý¿âϵͳ£¬¶øÿ¸öµØÊƵĿìѶÓÖһЩ¹²Í¬µÄ£¬Æ©ÈçͻȻ³öÁËÒ»Ìõ¹ú¼ÊÐÂÎÅ£¬ÄÇôÊDz»ÊÇÿ¸öµØÊƵĺǫ́±à¼¶¼ÒªÂ¼ÈëÒ»±é£¬ÕâÑùÎÞÒÉÊÇ×öÁËÐí¶àÎÞÓù¦£¬ËùÒÔ¹«Ë¾¿¼ÂǼÜÉèÒ»¸ö×ÜÕ¾£¬×ÜÕ¾ÉÏÓÐרÃŵÄÈ˸ºÔð£¬Ã¿Ì츺Ôð¼ÈëÒ» ......
»ù±¾µÄSql±àдעÒâÊÂÏî
¾¡Á¿ÉÙÓÃIN²Ù×÷·û£¬»ù±¾ÉÏËùÓеÄIN²Ù×÷·û¶¼¿ÉÒÔÓÃEXISTS´úÌæ¡£
²»ÓÃNOT IN²Ù×÷·û£¬¿ÉÒÔÓÃNOT EXISTS»òÕßÍâÁ¬½Ó+Ìæ´ú¡£
OracleÔÚÖ´ÐÐIN×Ó²éѯʱ£¬Ê×ÏÈÖ´ÐÐ×Ó²éѯ£¬½«²éѯ½á¹û·ÅÈëÁÙʱ±íÔÙÖ´ÐÐÖ÷²éѯ¡£¶øEXISTÔòÊÇÊ×Ïȼì²éÖ÷²éѯ£¬È»ºóÔËÐÐ×Ó²éѯֱµ½ÕÒµ½
µÚÒ»¸öÆ¥ÅäÏî¡£NOT EXISTS±ÈNOT INЧÂÊÉ ......