sql²éѯÓï¾äÖÐ inºÍ existsµÄÇø±ðÓëÐÔÄܱȽÏ
¶ÔInºÍexistsµÄÐÔÄܽøÐбȽϣ¬Ê×ÏÈÒªÖªµÀËüÃÇÁ½ÕßµÄÇø±ð¡£
in: È·¶¨¸ø¶¨µÄÖµÊÇ·ñÓë×Ó²éѯÖеÄÖµ»òÁбíÖеÄÖµÏàÆ¥Åä¡£
exists: Ö¸¶¨Ò»¸ö×Ó²éѯ£¬¼ì²âÐÐÊÇ·ñ´æÔÚ¡£
¿É·ÖÎöËüÃǵIJéѯÓï¾äÀ´µÃ³öÕæÊµµÄ²î±ð:
in
±ÈÈçSelect * from t1 where x in ( select y from t2 )
Ö´ÐеĹý³ÌÏ൱ÓÚ:
select *
from t1, ( select distinct y from t2 ) t2
where t1.x = t2.y;
exists
±ÈÈçselect * from t1 where exists ( select t2.z from t2 where y = x )
Ö´ÐеĹý³ÌÏ൱ÓÚ:
for t in ( select * from t1 )
loop
if ( exists ( select t2.z from t2 where y = t.x )
then
OUTPUT THE RECORD
end if
end loop
´ÓÉÏÃæµÄÓï¾ä¿ÉÒÔ¿´³ö£¬¶Ôt1±í²»¿É±ÜÃâµÄ½øÐÐÁËÒ»´ÎÈ«ÅÌɨÃè
inºÍexists
in ÊǰÑÍâ±íºÍÄÚ±í×÷hash Á¬½Ó£¬¶øexistsÊǶÔÍâ±í×÷loopÑ»·£¬Ã¿´ÎloopÑ»·ÔÙ¶ÔÄÚ±í½øÐвéѯ¡£
Ò»Ö±ÒÔÀ´ÈÏΪexists±ÈinЧÂʸߵÄ˵·¨ÊDz»×¼È·µÄ¡£
Èç¹û²éѯµÄÁ½¸ö±í´óСÏ൱£¬ÄÇôÓÃinºÍexists²î±ð²»´ó¡£
Èç¹ûÁ½¸ö±íÖÐÒ»¸ö½ÏС£¬Ò»¸öÊÇ´ó±í£¬Ôò×Ó²éѯ±í´óµÄÓÃexists£¬×Ó²éѯ±íСµÄÓÃin£º
ÀýÈ磺±íA£¨Ð¡±í£©£¬±íB£¨´ó±í£©
1£º
select * from A where cc in (select cc from B)
ЧÂʵͣ¬Óõ½ÁËA±íÉÏccÁеÄË÷Òý£»
select * from A where exists(select cc from B where cc=A.cc)
ЧÂʸߣ¬Óõ½ÁËB±íÉÏccÁеÄË÷Òý¡£
Ïà·´µÄ
2£º
select * from B where cc in (select cc from A)
ЧÂʸߣ¬Óõ½ÁËB±íÉÏccÁеÄË÷Òý£»
select * from B where exists(select cc from A where cc=B.cc)
ЧÂʵͣ¬Óõ½ÁËA±íÉÏccÁеÄË÷Òý¡£
not in ºÍnot exists
Èç¹û²éѯÓï¾äʹÓÃÁËnot in ÄÇôÄÚÍâ±í¶¼½øÐÐÈ«±íɨÃ裬ûÓÐÓõ½Ë÷Òý£»
¶ønot extsts µÄ×Ó²éѯÒÀÈ»ÄÜÓõ½±íÉϵÄË÷Òý¡£
ËùÒÔÎÞÂÛÄǸö±í´ó£¬ÓÃnot exists¶¼±Ènot inÒª¿ì¡£
Ïà¹ØÎĵµ£º
̽ÌÖÈçºÎÔÚÓÐ×Å1000ÍòÌõÊý¾ÝµÄMS SQL SERVERÊý¾Ý¿âÖÐʵÏÖ¿ìËÙµÄÊý¾ÝÌáÈ¡ºÍÊý¾Ý·ÖÒ³¡£ÒÔÏ´úÂë˵Ã÷ÁËÎÒÃÇʵÀýÖÐÊý¾Ý¿âµÄ“ºìÍ·Îļþ”Ò»±íµÄ²¿·ÖÊý¾Ý½á¹¹£º
CREATE TABLE [dbo].[TGongwen] ( --TGongwenÊǺìÍ·Îļþ±íÃû
[Gid] [int]&nb ......
1.¼¤»îSQL¸ú×Ù
´Óoracle10gÒÔºóÌṩÁËÐµķ½·¨¼¤»îSQLµÄ¸ú×Ù£¬¼´ÊÇʹÓÃdbms_monitor°üÀ´¿ªÆô»ò¹Ø±ÕSQL¸ú×Ù¡£
֮ǰ¾É·½·¨ÊÇʹÓà alter session set events .. »òÕßʹÓÃdbms_system.set_ev·½Ê½
ʹÓÃdbms_monitor°ü¿ÉÒÔÔڻỰ£¬¿Í»§¶Ë£¬×é¼þÒÔ¼°Êý¾Ý¿âËĸö²ã¼¶¿ªÆôSQLµÄ¸ú×Ù¡ ......
Oracle
SQL
Loader
µÄÏêϸÓï·¨
Oracle
SQL
Loader
µÄÏêϸÓï·¨
SQL
*LOADER
ÊÇ
ORACLE
µÄÊý¾Ý¼ÓÔØ¹¤¾ß£¬Í¨³£ÓÃÀ´½«²Ù×÷ϵͳÎļþÇ¨ÒÆµ½
ORACLE
Êý¾Ý¿âÖС£
SQL
*LOADER
ÊÇ´óÐÍÊý¾Ý
²Ö¿âÑ¡ÔñʹÓõļÓÔØ·½·¨£¬ÒòΪËüÌṩÁË×î¿ì ......
ͨ³£Çé¿öÏ£¬SQL ServerÀïÃæµÄÉú³ÉSQL½Å±¾£¬Ö»»á°üº¬Êý¾Ý¿â¼°±íµÄ×ֶνṹ£¬¶ø²»»á°üº¬±íµÄÊý¾Ý£¬Ò²¾ÍÊÇSQL½Å±¾ÀïÃæÖ»ÓÐCreate database£¬Create table ÕâÑùµÄÓï¾ä£¬Ã»ÓÐinsert into¡£
ÒòΪSQL Server²¢²»°üº¬Õâ¸ö¹¦ÄÜ£¬Ö»ÄÜ¿¿µÚÈý·½µÄ´úÂëÁË¡£
ÒÔÏ´洢¹ý³Ì¿ÉÒÔʵÏÖ£º
CREATE PROCEDURE dbo.UspOutputData
@tablenam ......
ÏÈ¿ªÆô·þÎñÆ÷ÅäÖÃÑ¡Ï
EXEC sp_configure 'show advanced options', 1
RECONFIGURE
EXEC sp_configure 'xp_cmdshell', 1
RECONFIGURE
/** µ¼³öÎı¾Îļþ
EXEC master..xp_cmdshell 'bcp dbname..tablename out c:\DT.txt -c -S servername -U sa -P password'
»ò
EXEC master..xp_cmdshell ' ......