oracleÊ÷½á¹¹²éѯ
connect by Êǽṹ»¯²éѯÖÐÓõ½µÄ£¬Æä»ù±¾Óï·¨ÊÇ£º
select ... from tablename start with Ìõ¼þ1
connect by Ìõ¼þ2
where Ìõ¼þ3;
Àý£º
select * from table
start with org_id = 'HBHqfWGWPy'
connect by prior org_id = parent_id;
¼òµ¥ËµÀ´Êǽ«Ò»¸öÊ÷×´½á¹¹´æ´¢ÔÚÒ»ÕűíÀ±ÈÈçÒ»¸ö±íÖдæÔÚÁ½¸ö×Ö¶Î:
org_id,parent_idÄÇôͨ¹ý±íʾÿһÌõ¼Ç¼µÄparentÊÇË£¬¾Í¿ÉÒÔÐγÉÒ»¸öÊ÷×´½á¹¹¡£
ÓÃÉÏÊöÓï·¨µÄ²éѯ¿ÉÒÔÈ¡µÃÕâ¿ÃÊ÷µÄËùÓмǼ¡£
ÆäÖУº
Ìõ¼þ1 ÊǸù½áµãµÄÏÞ¶¨Óï¾ä£¬µ±È»¿ÉÒÔ·Å¿íÏÞ¶¨Ìõ¼þ£¬ÒÔÈ¡µÃ¶à¸ö¸ù½áµã£¬Êµ¼Ê¾ÍÊǶà¿ÃÊ÷¡£
Ìõ¼þ2 ÊÇÁ¬½ÓÌõ¼þ£¬ÆäÖÐÓÃPRIOR±íʾÉÏÒ»Ìõ¼Ç¼£¬±ÈÈç CONNECT BY PRIOR org_id
= parent_id¾ÍÊÇ˵ÉÏÒ»Ìõ¼Ç¼µÄorg_id ÊDZ¾Ìõ¼Ç¼µÄparent_id£¬¼´±¾¼Ç¼µÄ¸¸Ç×ÊÇÉÏÒ»Ìõ¼Ç¼¡£
Ìõ¼þ3 ÊǹýÂËÌõ¼þ£¬ÓÃÓÚ¶Ô·µ»ØµÄËùÓмǼ½øÐйýÂË¡£
¼òµ¥½éÉÜÈçÏ£º
ÔçɨÃèÊ÷½á¹¹±íʱ£¬ÐèÒªÒÀ´Ë·ÃÎÊÊ÷½á¹¹µÄÿ¸ö½Úµã£¬Ò»¸ö½ÚµãÖ»ÄÜ·ÃÎÊÒ»´Î£¬Æä·ÃÎʵIJ½ÖèÈçÏ£º
µÚÒ»²½£º´Ó¸ù½Úµã¿ªÊ¼£»
µÚ¶þ²½£º·ÃÎʸýڵ㣻
µÚÈý²½£ºÅжϸýڵãÓÐÎÞδ±»·ÃÎʵÄ×ӽڵ㣬ÈôÓУ¬ÔòתÏòËü×î×ó²àµÄδ±»·ÃÎʵÄ×Ó½Ú£¬²¢Ö´Ðеڶþ²½£¬·ñÔòÖ´ÐеÚËIJ½£»
µÚËIJ½£ºÈô¸Ã½ÚµãΪ¸ù½Úµã£¬Ôò·ÃÎÊÍê±Ï£¬·ñÔòÖ´ÐеÚÎå²½£»
µÚÎå²½£º·µ»Øµ½¸Ã½ÚµãµÄ¸¸½Úµã£¬²¢Ö´ÐеÚÈý²½Öè¡£
×ÜÖ®£ºÉ¨ÃèÕû¸öÊ÷½á¹¹µÄ¹ý³ÌÒ²¼´ÊÇÖÐÐò±éÀúÊ÷µÄ¹ý³Ì¡£
1£® Ê÷½á¹¹µÄÃèÊö
Ê÷½á¹¹µÄÊý¾Ý´æ·ÅÔÚ±íÖУ¬Êý¾ÝÖ®¼äµÄ²ã´Î¹Øϵ¼´¸¸×Ó¹Øϵ£¬Í¨¹ý±íÖеÄÁÐÓëÁмäµÄ¹ØϵÀ´ÃèÊö£¬
ÈçEMP±íÖеÄEMPNOºÍMGR¡£EMPNO±íʾ¸Ã¹ÍÔ±µÄ±àºÅ£¬MGR±íʾÁìµ¼¸Ã¹ÍÔ±µÄÈ˵ıàºÅ£¬¼´×Ó½ÚµãµÄMGRÖµµÈÓÚ¸¸½ÚµãµÄEMPNOÖµ¡£ÔÚ±íµÄ
ÿһÐÐÖж¼ÓÐÒ»¸ö±íʾ¸¸½ÚµãµÄMGR£¨³ý¸ù½ÚµãÍ⣩£¬Í¨¹ýÿ¸ö½ÚµãµÄ¸¸½Úµã£¬¾Í¿ÉÒÔÈ·¶¨Õû¸öÊ÷½á¹¹¡£
ÔÚSELECTÃüÁîÖÐʹÓÃCONNECT BY ºÍ°ªSTART WITH
×Ó¾ä¿ÉÒÔ²éѯ±íÖеÄÊ÷Ðͽṹ¹Øϵ¡£ÆäÃüÁî¸ñʽÈçÏ£º
SELECT ¡£¡£¡£
CONNECT BY {PRIOR ÁÐÃû1=ÁÐÃû2|ÁÐÃû1=PRIOR ÁÑÃû2}
[START WITH]£»
ÆäÖУºCONNECT
BY×Ó¾ä˵Ã÷ÿÐÐÊý¾Ý½«ÊÇ°´²ã´Î˳Ðò¼ìË÷£¬²¢¹æ¶¨½«±íÖеÄÊý¾ÝÁ¬ÈëÊ÷ÐͽṹµÄ¹ØϵÖС£PRIORYÔËËã·û±ØÐë·ÅÖÃÔÚÁ¬½Ó¹ØϵµÄÁ½ÁÐÖÐijһ¸öµÄÇ°Ãæ¡£¶ÔÓÚ½Ú
µã¼äµÄ¸¸×Ó¹Øϵ£¬PRIORÔËËã·ûÔÚÒ»²à±íʾ¸¸½Úµã£¬ÔÚÁíÒ»²à±íʾ×ӽڵ㣬´Ó¶øÈ·¶¨²éÕÒÊ÷½á¹¹ÊǵÄ˳ÐòÊÇ×Ô¶¥ÏòÏ»¹ÊÇ×Ôµ×ÏòÉÏ¡£ÔÚÁ¬½Ó¹ØϵÖУ¬³ýÁË¿ÉÒÔʹ
ÓÃÁÐÃûÍ⣬»¹ÔÊÐíʹÓÃÁбí´ï
Ïà¹ØÎĵµ£º
×î½üÔÚʹÓùý³ÌÖеķ¢ÏÖÁ¬½ÓÊý¾Ý¿âʱºÃʱ»µ£¬¾³£±¨TNSÒì³££¬ÔÚ¿ØÖÆÃæ°åÖÐÔÚ·þÎñÖн«tnsÕý³£Æô¶¯ºó£¬µ±Á¬½ÓÊý¾Ý¿âʱ·¢ÏÖtnsÓÖÍ£Ö¹ÁË¡£¿à¿àÔÚÍøÉÏËÑÑ°ÁËÐí¶à£¬·¢ÏÖÍøÉÏÆÌÌì¸ÇµØµÄÈýÖÖ·½·¨£¬ÎÒÒ»Ò»ÊÔÁ˶¼Ã»ÓÐ×÷Óá£
ºóÀ´ÎÞÒâÖп´µ½Ò»Î»ÍøÓÑ˵Ëû³öÏÖ¹ýÏàͬµÄÎÊÌ⣬ÊÇÓÉÓÚ×°Á˸övpnÈí¼þ£¬ÕâʱµÄÎÒÉñ¾ÌرðÃô ......
ORACLEÖÕÓÚÔÚ10GÖÐÌṩÁ˶ÔÕýÔò±í´ïʽµÄÖ§³Ö£¬ÒÔÇ°ÄÇЩÐèҪͨ¹ýLIKEÀ´½øÐеĸ´ÔÓµÄÆ¥Åä¾Í¿ÉÒÔͨ¹ýʹÓÃÕýÔò±í´ïʽ¸ü¼òµ¥µÄʵÏÖ¡£
Oracle 10gÕýÔò±í´ïʽÌá¸ßÁËSQLÁé»îÐÔ¡£ÓÐЧµÄ½â¾öÁËÊý¾ÝÓÐЧÐÔ£¬ Öظ´´ÊµÄ±æÈÏ, Î޹صĿհ׼ì²â£¬»òÕß·Ö½â¶à¸öÕýÔò×é³ÉµÄ×Ö·û´®µÈÎÊÌâ¡£
Oracle 10gÖ§³ÖÕýÔò±í´ïʽµÄË ......
Ç°¼¸¸öÏîÄ¿×Ô¼ºÃ»ÓÐд¹ý½Ó¿Ú£¬¶¼ÊǸºÔðǰ̨µÄ¿ØÖÆ¡£À´µ½Õâ¸öÏîÄ¿ÉÏ£¬²Å¿ªÊ¼×Ô¼ºÐ´£¬ÎÒÊÇ6ÔÂÖÐÑ®¿ªÊ¼×öÕâ¸öÏîÄ¿µÄ£¬ÏÖÔÚ11Ô·ݣ¬ÏÖÔÚÔÚÈ¥¿´6Ô·ÝдµÄpackage,¼òÖ±ÓеãÏëÍÂÁË¡£ÔÒòÓÐÒÔϼ¸µã£º
1. ¼ò½à£¬¶óÒªµÄ˵Ã÷ûÓи½¼Ó¡£
2. n¶à¹¦ÄÜ×ۺϵ½Ò»Æð£¬È«²¿·Åµ½Ò»¸ö°üÀ¶ø²»ÊǸù¾Ý¹¦ÄÜÄ£¿é»®·Ö¡£
3. ûÓÐÀýÍâ¿ØÖÆ¡£ ......
emctl start dbconsole ÊÇ10gµÄÆô¶¯console·þÎñµÄÃüÁî
½«OEM·þÎñÍ£Ö¹emctl stop dbconsole
emctl start dbconsoleÆô¶¯EM console·þÎñ£¬Ê¹ÓÃÇ°ÐèÒªÏÈÉèÖÃORACLE_SID»·¾³±äÁ¿
emctl stop dbconsoleÍ£Ö¹EM console·þÎñ£¬Ê¹ÓÃÇ°ÐèÒªÏÈÉèÖÃORACLE_SID»·¾³±äÁ¿
¹Ø±ÕÊý¾Ý¿âºóÓ¦¸ÃÊ×ÏÈÓÃsysdbaµÇ½,ÕâÑù¾Í½øÈëÁËsysģʽ. ......
Õ⼸Ìì×öÏîÄ¿Óöµ½ÁËǧÍò¼¶±íµÄ´¦Àí£¬Ïà¹ØÓÅ»¯µÄÐĵÃÌؼǼÏÂÀ´£¬ÒÔÇ°ÈÕºó²é¿´¡£
ÊÕ¼¯Í³¼Æ±íÐÅÏ¢ÓÐ2ÖÖ·½·¨£º
1: ANALYZE TABLE employees COMPUTE STATISTICS;
2: exec dbms_stats.gather_table_stats(ownname => 'owner_name',tabname => 'table_name' ,estimate_percent => null ,method_o ......