Oracle SqlÓÅ»¯±Ê¼Ç(Ò»)
»ù±¾µÄSql±àдעÒâÊÂÏî
¾¡Á¿ÉÙÓÃIN²Ù×÷·û£¬»ù±¾ÉÏËùÓеÄIN²Ù×÷·û¶¼¿ÉÒÔÓÃEXISTS´úÌæ¡£
²»ÓÃNOT IN²Ù×÷·û£¬¿ÉÒÔÓÃNOT EXISTS»òÕßÍâÁ¬½Ó+Ìæ´ú¡£
OracleÔÚÖ´ÐÐIN×Ó²éѯʱ£¬Ê×ÏÈÖ´ÐÐ×Ó²éѯ£¬½«²éѯ½á¹û·ÅÈëÁÙʱ±íÔÙÖ´ÐÐÖ÷²éѯ¡£¶øEXISTÔòÊÇÊ×Ïȼì²éÖ÷²éѯ£¬È»ºóÔËÐÐ×Ó²éѯֱµ½ÕÒµ½µÚÒ»¸öÆ¥ÅäÏî¡£NOT EXISTS±ÈNOT INЧÂÊÉԸߡ£µ«¾ßÌåÔÚÑ¡ÔñIN»òEXIST²Ù×÷ʱ£¬Òª¸ù¾ÝÖ÷×Ó±íÊý¾ÝÁ¿´óСÀ´¾ßÌ忼ÂÇ¡£
²»ÓÓ<>”»òÕß“!=”²Ù×÷·û¡£¶Ô²»µÈÓÚ²Ù×÷·ûµÄ´¦Àí»áÔì³ÉÈ«±íɨÃ裬¿ÉÒÔÓÓ<” or “>”´úÌæ¡£
Where×Ó¾äÖгöÏÖIS NULL»òÕßIS NOT NULLʱ£¬Oracle»áֹͣʹÓÃË÷Òý¶øÖ´ÐÐÈ«±íɨÃè¡£¿ÉÒÔ¿¼ÂÇÔÚÉè¼Æ±íʱ£¬¶ÔË÷ÒýÁÐÉèÖÃΪNOT NULL¡£ÕâÑù¾Í¿ÉÒÔÓÃÆäËû²Ù×÷À´È¡´úÅжÏNULLµÄ²Ù×÷¡£
µ±Í¨Åä·û“%”»òÕß“_”×÷Ϊ²éѯ×Ö·û´®µÄµÚÒ»¸ö×Ö·ûʱ£¬Ë÷Òý²»»á±»Ê¹Óá£
¶ÔÓÚÓÐÁ¬½ÓµÄÁГ||”£¬×îºóÒ»¸öÁ¬½ÓÁÐË÷Òý»áÎÞЧ¡£¾¡Á¿±ÜÃâÁ¬½Ó£¬¿ÉÒÔ·Ö¿ªÁ¬½Ó»òÕßʹÓò»×÷ÓÃÔÚÁÐÉϵĺ¯ÊýÌæ´ú¡£
Èç¹ûË÷Òý²»ÊÇ»ùÓÚº¯ÊýµÄ£¬ÄÇôµ±ÔÚWhere×Ó¾äÖжÔË÷ÒýÁÐʹÓú¯Êýʱ£¬Ë÷Òý²»ÔÙÆð×÷Óá£
Where×Ó¾äÖбÜÃâÔÚË÷ÒýÁÐÉÏʹÓüÆË㣬·ñÔò½«µ¼ÖÂË÷ÒýʧЧ¶ø½øÐÐÈ«±íɨÃè¡£
¶ÔÊý¾ÝÀàÐͲ»Í¬µÄÁнøÐбȽÏʱ£¬»áʹË÷ÒýʧЧ¡£
ÓÓ>=”Ìæ´ú“>”¡£
UNION²Ù×÷·û»á¶Ô½á¹û½øÐÐɸѡ£¬Ïû³ýÖظ´£¬Êý¾ÝÁ¿´óµÄÇé¿öÏ¿ÉÄÜ»áÒýÆð´ÅÅÌÅÅÐò¡£Èç¹û²»ÐèҪɾ³ýÖظ´¼Ç¼£¬Ó¦¸ÃʹÓÃUNION ALL¡£
Oracle´Óϵ½ÉÏ´¦ÀíWhere×Ó¾äÖжà¸ö²éѯÌõ¼þ£¬ËùÒÔ±íÁ¬½ÓÓï¾äӦдÔÚÆäËûWhereÌõ¼þÇ°£¬¿ÉÒÔ¹ýÂ˵ô×î´óÊýÁ¿¼Ç¼µÄÌõ¼þ±ØÐëдÔÚWhere×Ó¾äµÄĩβ¡£
Oracle´ÓÓÒµ½×ó´¦Àífrom×Ó¾äÖеıíÃû£¬ËùÒÔÔÚfrom×Ó¾äÖаüº¬¶à¸ö±íµÄÇé¿öÏ£¬½«¼Ç¼×îÉٵıí·ÅÔÚ×îºó¡££¨Ö»ÔÚ²ÉÓÃRBOÓÅ»¯Ê±ÓÐЧ£¬ÏÂÎÄÏêÊö£©
Order ByÓï¾äÖеķÇË÷ÒýÁлήµÍÐÔÄÜ£¬¿ÉÒÔͨ¹ýÌí¼ÓË÷ÒýµÄ·½Ê½´¦Àí¡£Ñϸñ¿ØÖÆÔÚOrder ByÓï¾äÖÐʹÓñí´ïʽ¡£
²»Í¬ÇøÓò³öÏÖµÄÏàͬµÄSqlÓï¾ä£¬Òª±£Ö¤²éѯ×Ö·ûÍêÈ«Ïàͬ£¬ÒÔÀûÓÃSGA¹²Ïí³Ø£¬·ÀÖ¹ÏàͬµÄSqlÓï¾ä±»¶à´Î·ÖÎö¡£
¶àÀûÓÃÄÚ²¿º¯ÊýÌá¸ßSqlЧÂÊ¡£
µ±ÔÚSqlÓï¾äÖÐÁ¬½Ó¶à¸ö±íʱ£¬Ê¹ÓñíµÄ±ðÃû£¬²¢½«Ö®×÷ΪÿÁеÄǰ׺¡£ÕâÑù¿ÉÒÔ¼õÉÙ½âÎöʱ¼ä¡£
ÐèҪעÒâµÄÊÇ£¬Ëæ×ÅOracleµÄÉý¼¶£¬²éѯÓÅ»¯Æ÷»á×Ô¶¯¶ÔSqlÓï¾ä½øÐÐÓÅ»¯£¬Ä³Ð©ÏÞÖÆ¿ÉÄÜÔÚа汾µÄOracleϲ»ÔÙÊÇÎÊÌâ¡£ÓÈÆäÊDzÉÓÃCBO£¨Cost-Based Optimizati
Ïà¹ØÎĵµ£º
SELECT
(case when a.colorder=1 then d.name else '' end)±íÃû,
a.colorder ×Ö¶ÎÐòºÅ,
a.name ×Ö¶ÎÃû,
(case when COLUMNPROPERTY( a.id,a.name,'IsIdentity ......
²éѯËÙ¶ÈÂýµÄÔÒòºÜ¶à£¬³£¼ûÈçϼ¸ÖÖ
1¡¢Ã»ÓÐË÷Òý»òÕßûÓÐÓõ½Ë÷Òý(ÕâÊDzéѯÂý×î³£¼ûµÄÎÊÌ⣬ÊdzÌÐòÉè¼ÆµÄȱÏÝ)
2¡¢I/OÍÌÍÂÁ¿Ð¡£¬ÐγÉÁËÆ¿¾±Ð§Ó¦¡£
3¡¢Ã»Óд´ ......
1£® ÅжÏa±íÖÐÓжøb±íÖÐûÓеļǼ
select a.* from tbl1 a
left join tbl2 b
on a.key = b.key
where b.key is null
ËäȻʹÓÃinÒ²¿ÉÒÔʵÏÖ£¬µ«ÊÇÕâÖÖ·½·¨µÄЧÂʸü¸ßһЩ
2£® н¨Ò»¸öÓëij¸ö±íÏàͬ½á¹¹µÄ±í
select * into b
from a where 1<>1
3£®betwee ......
ÏÈ˵˵ÕâЩÎóÇø¡£Ëùν“ÎóÇø”£¬ÓÐһЩÊÇÐÂÊÖºÜÈÝÒ×·¸µÄ´íÎó»òÕߺÜÈÝÒ׺öÂÔµÄÎÊÌ⣬ÁíÍâһЩ£¬ÔòÊÇÏñ“ºÄ×Ó³ÔÁËÑλá±ä³Éòùòð”Ò»Ñù£¬ÈÃÎÒÃÇ´ÓС¾ÍÈÏΪÊÇÕýÈ·µÄÊÂÇé¡£ÈçÏ£º
1¡¢ ±íÉϲ»¹ÜÓõÃ×ÅÓò»×Å£¬¶¼¼Ó¸ö¾Û¼¯Ë÷Òý¡£
ÎÒÃÇÖªµÀ£¬±íÒÔÁ½ÖÖ·½Ê½×éÖ¯ÎïÀí´æ´¢£ºÓоۼ¯Ë÷ÒýµÄ“¾Û¼¯±í&r ......
¹ØÓÚ±¾Îı¾ÎÄËùÃè»æµÄ¹¦Äܺͼƻ®ÊÇÏÂÒ»°æ±¾ SQL Server µÄ¿ª·¢·½Ïò¡£ËüÃDz¢·Ç±¾²úÆ·µÄ˵Ã÷Ê飬ÈçÓиü¸Ä£¬Ë¡²»ÁíÐÐ֪ͨ¡£¶ÔÓÚ×îÖÕ²úÆ·ÊÇ·ñ¾ßÓÐÕâЩ¹¦Äܲ»×öÈκÎÃ÷ʾ»ò°µÊ¾µÄ±£Ö¤¡£¶ÔÓÚijЩ¹¦ÄÜ£¬±¾ÎļÙÉè¶ÁÕßÊìϤ SQL Server 2000 ¹¦ÄܺͷþÎñ¡£Óйر³¾°ÐÅÏ¢£¬Çë·ÃÎÊSQL Server ÍøÕ¾»ò SQL Server 2000 ×ÊÔ´¹¤¾ß°ü¡£Õâ²¢²»Ê ......