Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

ÒªÌá¸ßSQL²éѯЧÂÊwhereÓï¾äÌõ¼þµÄÏȺó´ÎÐòÓ¦ÈçºÎд

ÎÒÃÇÒª×öµ½²»µ«»áдSQL£¬»¹Òª×öµ½Ð´³öÐÔÄÜÓÅÁ¼µÄSQLÓï¾ä¡£
£¨1£©Ñ¡Ôñ×îÓÐЧÂʵıíÃû˳Ðò(Ö»ÔÚ»ùÓÚ¹æÔòµÄÓÅ»¯Æ÷ÖÐÓÐЧ)£º
OracleµÄ½âÎöÆ÷°´ÕÕ´ÓÓÒµ½×óµÄ˳Ðò´¦Àífrom×Ó¾äÖеıíÃû£¬from×Ó¾äÖÐдÔÚ×îºóµÄ±í(»ù´¡±í driving
table)½«±»×îÏÈ´¦Àí£¬ÔÚfrom×Ó¾äÖаüº¬¶à¸ö±íµÄÇé¿öÏÂ,Äã±ØÐëÑ¡Ôñ¼Ç¼ÌõÊý×îÉٵıí×÷Ϊ»ù´¡±í¡£Èç¹ûÓÐ3¸öÒÔÉϵıíÁ¬½Ó²éѯ,
ÄǾÍÐèҪѡÔñ½»²æ±í(intersection table)×÷Ϊ»ù´¡±í, ½»²æ±íÊÇÖ¸ÄǸö±»ÆäËû±íËùÒýÓÃµÄ±í¡£
£¨2£©WHERE×Ó¾äÖеÄÁ¬½Ó˳Ðò£º
Oracle²ÉÓÃ×Ô϶øÉϵÄ˳Ðò½âÎöWHERE×Ó¾ä,¸ù¾ÝÕâ¸öÔ­Àí,±íÖ®¼äµÄÁ¬½Ó±ØÐëдÔÚÆäËûWHEREÌõ¼þ֮ǰ,
ÄÇЩ¿ÉÒÔ¹ýÂ˵ô×î´óÊýÁ¿¼Ç¼µÄÌõ¼þ±ØÐëдÔÚWHERE×Ó¾äµÄĩβ¡£ ÖÐ.¹ú.Õ¾³¤Õ¾
£¨3£©SELECT×Ó¾äÖбÜÃâʹÓÑ*’£º
OracleÔÚ½âÎöµÄ¹ý³ÌÖÐ, »á½«‘*’ÒÀ´Îת»»³ÉËùÓеÄÁÐÃû, Õâ¸ö¹¤×÷ÊÇͨ¹ý²éѯÊý¾Ý×ÖµäÍê³ÉµÄ, ÕâÒâζ׎«ºÄ·Ñ¸ü¶àµÄʱ¼ä¡£
£¨4£©¼õÉÙ·ÃÎÊÊý¾Ý¿âµÄ´ÎÊý£º
OracleÔÚÄÚ²¿Ö´ÐÐÁËÐí¶à¹¤×÷: ½âÎöSQLÓï¾ä, ¹ÀËãË÷ÒýµÄÀûÓÃÂÊ, °ó¶¨±äÁ¿ , ¶ÁÊý¾Ý¿éµÈ¡£
£¨5£©ÔÚSQL*Plus , SQL*FormsºÍPro*CÖÐÖØÐÂÉèÖÃARRAYSIZE²ÎÊý, ¿ÉÒÔÔö¼Óÿ´ÎÊý¾Ý¿â·ÃÎʵļìË÷Êý¾ÝÁ¿
,½¨ÒéֵΪ200¡£
£¨6£©Ê¹ÓÃDECODEº¯ÊýÀ´¼õÉÙ´¦Àíʱ¼ä£º
ʹÓÃDECODEº¯Êý¿ÉÒÔ±ÜÃâÖظ´É¨ÃèÏàͬ¼Ç¼»òÖظ´Á¬½ÓÏàͬµÄ±í¡£
£¨7£©ÕûºÏ¼òµ¥,ÎÞ¹ØÁªµÄÊý¾Ý¿â·ÃÎÊ£º
Èç¹ûÄãÓм¸¸ö¼òµ¥µÄÊý¾Ý¿â²éѯÓï¾ä,Äã¿ÉÒÔ°ÑËüÃÇÕûºÏµ½Ò»¸ö²éѯÖÐ(¼´Ê¹ËüÃÇÖ®¼äûÓйØϵ)¡£
£¨8£©É¾³ýÖظ´¼Ç¼£º
×î¸ßЧµÄɾ³ýÖظ´¼Ç¼·½·¨ ( ÒòΪʹÓÃÁËROWID)Àý×Ó£º
DELETE from EMP E WHERE E.ROWID > (SELECT MIN(X.ROWID) from EMP X
WHERE X.EMP_NO = E.EMP_NO);
£¨9£©ÓÃTRUNCATEÌæ´úDELETE£º
µ±É¾³ý±íÖеļǼʱ,ÔÚͨ³£Çé¿öÏÂ, »Ø¹ö¶Î(rollback segments ) ÓÃÀ´´æ·Å¿ÉÒÔ±»»Ö¸´µÄÐÅÏ¢.
Èç¹ûÄãûÓÐCOMMITÊÂÎñ,ORACLE»á½«Êý¾Ý»Ö¸´µ½É¾³ý֮ǰµÄ״̬(׼ȷµØ˵Êǻָ´µ½Ö´ÐÐɾ³ýÃüÁî֮ǰµÄ×´¿ö) ¶øµ±ÔËÓÃTRUNCATEʱ,
»Ø¹ö¶Î²»ÔÙ´æ·ÅÈκοɱ»»Ö¸´µÄÐÅÏ¢¡£µ±ÃüÁîÔËÐкó,Êý¾Ý²»Äܱ»»Ö¸´.Òò´ËºÜÉÙµÄ×ÊÔ´±»µ÷ÓÃ,Ö´ÐÐʱ¼äÒ²»áºÜ¶Ì¡££¨TRUNCATEÖ»ÔÚɾ³ýÈ«±íÊÊ
ÓÃ,TRUNCATEÊÇDDL²»ÊÇDML£©¡£ Chinaz_com
£¨10£©¾¡Á¿¶àʹÓÃCOMMIT£º
Ö»ÒªÓпÉÄÜ£¬ÔÚ³ÌÐòÖо¡Á¿¶àʹÓÃCOMMIT, ÕâÑù³ÌÐòµÄÐÔÄܵõ½Ìá¸ß,ÐèÇóÒ²»áÒòΪCOMMITËùÊͷŵÄ×ÊÔ´¶ø¼õÉÙ£¬COMMITËùÊͷŵÄ×ÊÔ´:
a. »Ø¹ö¶ÎÉÏÓÃÓÚ»Ö¸´Êý¾ÝµÄÐÅÏ¢¡£
b. ±»³ÌÐòÓï¾ä»ñµÃµÄ


Ïà¹ØÎĵµ£º

ÎÄ˼´´ÐµÄSQL±ÊÊÔÌâ


ÌâÄ¿£ºÓÐAºÍBÁ©¸ö±í£¬¶¼¶¨ÒåÏàͬµÄÖ÷¼ü£¬Ð´³öSQLÓï¾äÕÒ³öA±íÖÐÓжøB±íÖÐûÓеļǼ£¬È»ºó°ÑûÓеļǼ²åÈëµ½B±íÖС£
SQLÓï¾äÈçÏ£º
CREATE TABLE  A_MINUS_B  AS              ---´´½¨Ò»¸ö²î¼¯±íA_MINUS_B ,×¢ÒâSELECT Óï¾äÒ»¶¨ÒªA±íÔÚÇ°¡ ......

ÔÚsql*plusÏÂÉèÖÃautotrace

    ÎÒÃÇÔÚ¹¤×÷ÖÐÏ£ÍûÄÜ¿´¼û×Ô¼ºÔËÐеÄDMLÓï¾äµÄÔËÐб¨¸æ£¬ÀýÈçselect,delete,update,megreºÍinsertÓï¾äÔËÐкóµÄÇé¿ö£¬ÒÔÓÃÀ´¼àÊӺ͵÷ÓÅÓï¾ä¡£ÎÒÃÇͨ³£ÔÚsql*plusÖÐʹÓÃset autotrace on¿ªÆô¡£
    ÄÇautotraceÊÇÈçºÎ°²×°µÄÄØ£¿thomas kyteµÄ´ó×÷Öиø³öÁËÏêϸµÄ·½·¨ºÍ½âÊÍ£º
  & ......

hibernateÖ´ÐÐÔ­ÉúSqlÓï¾äµÄ·½·¨£¨×ª£©

http://www.thecloud.cn/study/program/java/597.html
hibernate3µÄHQL ÊÇÃæÏò¶ÔÏóµÄÓï·¨,ÒѾ­Ö§³Ö update ,delete fromÓï¾ä,µ«
Ä¿Ç°»¹²»Ö§³Öinsert intoÓï¾ä.
×öÏîÄ¿ÓÐʱºòµÄÈ·ÐèҪдԭÉúµÄsqlÀ´·½±ãweb¿ª·¢.
ÏÂÃæÊÇÎÒ×Ô¼º¹Äµ·³öÀ´µÄ·½·¨,Ï£Íû¶ÔÎÒºÍÅóÓÑÓÐËù°ïÖú.
ÔÚDaoÀïдһ¸ö·½·¨,ÈÃÎÒÃÇÔÚactionÀïµ÷ÓÃËü...
&nbs ......

sql overµÄ×÷Óü°Ó÷¨


RANK ( ) OVER ( [query_partition_clause] order_by_clause )
DENSE_RANK ( ) OVER ( [query_partition_clause] order_by_clause )
¿ÉʵÏÖ°´Ö¸¶¨µÄ×ֶηÖ×éÅÅÐò£¬¶ÔÓÚÏàͬ·Ö×é×ֶεĽá¹û¼¯½øÐÐÅÅÐò,
ÆäÖÐPARTITION BY Ϊ·Ö×é×ֶΣ¬ORDER BY Ö¸¶¨ÅÅÐò×Ö¶Î
over²»Äܵ¥¶ÀʹÓã¬ÒªºÍ·ÖÎöº¯Êý£ºrank(),dense_rank(),row_n ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ