SQLÓÅ»¯¹ý³ÌÖг£¼ûOracle HINTµÄÓ÷¨
ÔÚSQLÓï¾äÓÅ»¯¹ý³ÌÖУ¬ÎÒÃǾ³£»áÓõ½hint,ÏÖ×ܽáÒ»ÏÂÔÚSQLÓÅ»¯¹ý³ÌÖг£¼ûOracle HINTµÄÓ÷¨£º
1. /*+ALL_ROWS*/
±íÃ÷¶ÔÓï¾ä¿éÑ¡Ôñ»ùÓÚ¿ªÏúµÄÓÅ»¯·½·¨,²¢»ñµÃ×î¼ÑÍÌÍÂÁ¿,ʹ×ÊÔ´ÏûºÄ×îС»¯.
ÀýÈç:
SELECT /*+ALL+_ROWS*/ EMP_NO,EMP_NAM,DAT_IN from BSEMPMS WHERE EMP_NO='SCOTT';
2. /*+FIRST_ROWS*/
±íÃ÷¶ÔÓï¾ä¿éÑ¡Ôñ»ùÓÚ¿ªÏúµÄÓÅ»¯·½·¨,²¢»ñµÃ×î¼ÑÏìӦʱ¼ä,ʹ×ÊÔ´ÏûºÄ×îС»¯.
ÀýÈç:
SELECT /*+FIRST_ROWS*/ EMP_NO,EMP_NAM,DAT_IN from BSEMPMS WHERE EMP_NO='SCOTT';
3. /*+CHOOSE*/
±íÃ÷Èç¹ûÊý¾Ý×ÖµäÖÐÓзÃÎʱíµÄͳ¼ÆÐÅÏ¢,½«»ùÓÚ¿ªÏúµÄÓÅ»¯·½·¨,²¢»ñµÃ×î¼ÑµÄÍÌÍÂÁ¿;
±íÃ÷Èç¹ûÊý¾Ý×ÖµäÖÐûÓзÃÎʱíµÄͳ¼ÆÐÅÏ¢,½«»ùÓÚ¹æÔò¿ªÏúµÄÓÅ»¯·½·¨;
ÀýÈç:
SELECT /*+CHOOSE*/ EMP_NO,EMP_NAM,DAT_IN from BSEMPMS WHERE EMP_NO='SCOTT';
4. /*+RULE*/
±íÃ÷¶ÔÓï¾ä¿éÑ¡Ôñ»ùÓÚ¹æÔòµÄÓÅ»¯·½·¨.
ÀýÈç:
SELECT /*+ RULE */ EMP_NO,EMP_NAM,DAT_IN from BSEMPMS WHERE EMP_NO='SCOTT';
5. /*+FULL(TABLE)*/
±íÃ÷¶Ô±íÑ¡ÔñÈ«¾ÖɨÃèµÄ·½·¨.
ÀýÈç:
SELECT /*+FULL(A)*/ EMP_NO,EMP_NAM from BSEMPMS A WHERE EMP_NO='SCOTT';
6. /*+ROWID(TABLE)*/
ÌáʾÃ÷È·±íÃ÷¶ÔÖ¸¶¨±í¸ù¾ÝROWID½øÐзÃÎÊ.
ÀýÈç:
SELECT /*+ROWID(BSEMPMS)*/ * from BSEMPMS WHERE ROWID>='AAAAAAAAAAAAAA'
AND EMP_NO='SCOTT';
7. /*+CLUSTER(TABLE)*/
ÌáʾÃ÷È·±íÃ÷¶ÔÖ¸¶¨±íÑ¡Ôñ´ØɨÃèµÄ·ÃÎÊ·½·¨,ËüÖ»¶Ô´Ø¶ÔÏóÓÐЧ.
ÀýÈç:
SELECT /*+CLUSTER */ BSEMPMS.EMP_NO,DPT_NO from BSEMPMS,BSDPTMS
WHERE DPT_NO='TEC304' AND BSEMPMS.DPT_NO=BSDPTMS.DPT_NO;
8. /*+INDEX(TABLE INDEX_NAME)*/
±íÃ÷¶Ô±íÑ¡ÔñË÷ÒýµÄɨÃè·½·¨.
ÀýÈç:
SELECT /*+INDEX(BSEMPMS SEX_INDEX) USE SEX_INDEX BECAUSE THERE ARE FEWMALE BSEMPMS */ from BSEMPMS WHERE SEX='M';
9. /*+INDEX_ASC(TABLE INDEX_NAME)*/
±íÃ÷¶Ô±íÑ¡ÔñË÷ÒýÉýÐòµÄɨÃè·½·¨.
ÀýÈç:
SELECT /*+INDEX_ASC(BSEMPMS PK_BSEMPMS) */ from BSEMPMS WHERE DPT_NO='SCOTT';
10. /*+INDEX_COMBINE*/
Ϊָ¶¨±íÑ¡Ôñλͼ·ÃÎÊ·¾,Èç¹ûINDEX_COMBINEÖÐûÓÐÌṩ×÷Ϊ²ÎÊýµÄË÷Òý,½«Ñ¡Ôñ³öλͼË÷ÒýµÄ²¼¶û×éºÏ·½Ê½.
ÀýÈç:
SELECT /*+INDEX_COMBINE(BSEMPMS SAL_BMI HIREDATE_BMI)*/ * from BSEMPMS
WHERE SAL <5000000 AND HIREDATE <SYSDATE;
11. /*+INDEX_JOIN(TA
Ïà¹ØÎĵµ£º
·Ï»°ÉÙ˵,(ÒѾÓоä·Ï»°ÁË.)
¿´±í
Óï¾ä: SELECT * from C
//---------------------------------------
Cno Cname Teacher
---- ---------- --------
1 ÓïÎÄ Æî¾²
2 &n ......
1) ʱ¼äת»»º¯ÊýÖÐÈç¹ûÓÐʱ¼ä±äÁ¿yyyy-mm-ddÁ½±ßÐèÁ½''
to_date(''' || to_char(a_valid_date_end, 'yyyy-mm-dd') ||''', ''yyyy-mm-dd'')
2) select distinct(e.itemnum) bulk collect into v_itemnum
½«×Ö·û´®Êý×éÒÔ·Ö¸ô·û·Ö¸ôµÄ×Ö·û´®µ÷ÓÃ
pkg_maximo_common.get_string(v_itemnum, ',', '')
3) unionÖ»Êǽ«Á½¸ö½á¹ ......
from:csdn
ÄÜ·ñÀûÓô¥·¢Æ÷²Ù×÷Ô¶³ÌÊý¾Ý¿â?
------------------------------------------------------------
-----01
------------------------------------------------------------
ÄÜ/********************Á´½ÓÊý¾Ý¿â *******************************/
exec OPENDA ......
UNION ÔËËã·û½«¶à¸ö SELECT Óï¾äµÄ½á¹û×éºÏ³ÉÒ»¸ö½á¹û¼¯¡£ £¨£±£©Ê¹Óà UNION ÐëÂú×ãÒÔÏÂÌõ¼þ£º £Á£ºËùÓвéѯÖбØÐë¾ßÓÐÏàͬµÄ½á¹¹£¨¼´²éѯÖеĵÄÁÐÊýºÍÁеÄ˳Ðò±ØÐëÏàͬ£©¡£ £Â£º¶ÔÓ¦ÁеÄÊý¾ÝÀàÐÍ¿ÉÒÔ²»Í¬µ«ÊDZØÐë¼æÈÝ£¨ËùνµÄ¼æÈÝÊÇÖ¸Á½ÖÖÀàÐÍÖ®¼ä¿ÉÒÔ½øÐÐÒþʽת»»£¬²»ÄܽøÐÐÒþʽת»»Ôò±¨´í£©¡£Ò²¿ÉÒÔÓÃÏÔʽת»»ÎªÏàͬµ ......
ÏÂÔصØÖ·£º http://download.csdn.net/source/1805903
private string ReArrange(string str)
{
string[] keywords = new string[] {"select","from","where","and","order\\s+by","or","into",
"update","set","delete","haveing" ......