Oracle ÖеÄÊ÷²éѯºÍ connect by
Oracle ÖеÄÊ÷²éѯºÍ connect by
ʹÓà connect by ºÍ start with À´½¨Á¢ÀàËÆÓÚÊ÷µÄ±¨±í²¢²»ÄÑ£¬Ö»Òª×ñÑÒÔÏ»ù±¾ÔÔò¼´¿É£º
ʹÓà connect by ʱ¸÷×Ó¾äµÄ˳ÐòӦΪ£º
select
from
where
start with
connect by
order by
prior ʹ±¨±íµÄ˳ÐòΪ´Ó¸ùµ½Ò¶£¨Èç¹û prior ÁÐÊǸ¸±²£©»ò´ÓÒ¶µ½¸ù£¨Èç¹û prior ÁÐÊǺó´ú£©¡£
where ×Ó¾ä¿ÉÒÔ´ÓÊ÷ÖÐÅųý¸öÌ壬µ«²»ÅųýËüÃǵÄ×ÓË»òÕß×æÏÈ£¬Èç¹û prior ÁÐÊǺó´ú£©¡£
connect by ÖеÄÌõ¼þ£¨ÓÈÆäÊDz»µÈÓÚ£©Ïû³ý¸öÌåºÍËüËùÓеÄ×ÓË»ò×æÏÈ£¬ÒÀÀµÓÚÔõÑù¸ú×ÙÊ÷£©¡£
connect by ²»ÄÜÓë where ×Ó¾äÖеıíÁ¬½ÓÔÚÒ»ÆðʹÓá£
ÏÂÃæÊǼ¸¸öÀý×Ó
1. ´Ó¸ùµ½Ò¶±éÀú
SELECT n_parendid, n_name, (LEVEL - 1), n_id
from navigation
WHERE n_parendid IS NOT NULL
START WITH n_id = 0
CONNECT BY n_parendid = PRIOR n_id;
2. ´ÓÒ¶µ½¸ù±éÀú
SELECT n_parendid, n_name, (LEVEL - 1), n_id
from navigation
WHERE n_parendid IS NOT NULL
START WITH n_id = 300
CONNECT BY n_id = PRIOR n_parendid;
3. Åųý¸öÌ壬µ«²»ÅųýËüÃǵÄ×ÓËï
SELECT n_parendid, n_name, (LEVEL - 1), n_id
from navigation
WHERE n_parendid IS NOT NULL AND n_id != 2
START WITH n_id = 0
CONNECT BY n_parendid = PRIOR n_id;
4. Ïû³ý¸öÌåºÍËüËùÓеÄ×ÓËï
SELECT n_parendid, n_name, (LEVEL - 1), n_id
from navigation
WHERE n_parendid IS NOT NULL
START WITH n_id = 0
CONNECT BY n_parendid = PRIOR n_id AND n_id != 2;
5. ¸Ä±äÏÔʾ˳Ðò
SELECT n_parendid, n_name, (LEVEL - 1), n_id
from navigation
WHERE n_parendid IS NOT NULL
START WITH n_id = 0
CONNECT BY n_parendid = PRIOR n_id
ORDER BY n_viewnum DESC;
±¾ÎÄת×Ôcsdn:http://blog.csdn.net/wzy0623/archive/2007/06/18/1656345.aspx
Ïà¹ØÎĵµ£º
Ò» µÇ¼SQLPLUS
sqlplusÓû§Ãû/ÃÜÂë@Êý¾Ý¿âʵÀýasµÇ¼½ÇÉ«;
Èç:Óû§sys(ÃÜÂëΪ123)ÒÔsysdbaµÄ½ÇÉ«µÇ¼Êý¾Ý¿âORACL£¬ÎÒÃÇ¿ÉÒÔÊäÈ룺sqlplus sys/123@oracl as sysdba;
ÕâÖֵǼ·½Ê½»áÖ±½Ó±©Â¶ÃÜÂ룬Èç¹ûÏëÒþ²ØÃÜÂ룬¿ÉÒÔÔÚ´ËÊ¡ÂÔÃÜÂëµÄÊäÈ룬È磺sqlplus sys@oracl as sysdb ......
[¾«»ª] ORACLEµÄ¼¸ÖÖÆô¶¯·½Ê½
http://www.chinaunix.net ×÷Õß:wuwenlong ·¢±íÓÚ£º2003-07-27 16:58:57
¡¾·¢±íÆÀÂÛ¡¿ ¡¾²é¿´ÔÎÄ¡¿ ¡¾OracleÌÖÂÛÇø¡¿¡¾¹Ø±Õ¡¿
1¡¢startup nomount
·Ç°²×°Æô¶¯£¬ÕâÖÖ·½Ê½Æô¶¯Ï¿ÉÖ´ÐУºÖؽ¨¿ØÖÆÎļþ¡¢Öؽ¨Êý¾Ý¿â
¶ÁÈ¡ ......
£¨Ò»£©Ê²Ã´½ÐÓû§£¨user£©£º
A user is a name defined in the database that can connect to and access objects.
Óû§ÊÇÓÃÁ¬½ÓÊý¾Ý¿âºÍ·ÃÎÊÊý¾Ý¿â¶ÔÏóµÄ¡££¨Óû§ÊÇÓÃÀ´Á¬½ÓÊý¾Ý¿â·ÃÎÊÊý¾Ý¿â£©¡£
£¨¶þ£©Ê²Ã´½Ðģʽ(schema)£º
A schema is a collection of database objects (used by a user.).
Schema objects are th ......
µ¥Öµº¯ÊýÔÚ²éѯÖзµ»Øµ¥¸öÖµ£¬¿É±»Ó¦Óõ½select£¬where×Ӿ䣬start withÒÔ¼°connect by ×Ó¾äºÍhaving×Ӿ䡣
(Ò»).ÊýÖµÐͺ¯Êý(Number Functions)
ÊýÖµÐͺ¯ÊýÊäÈëÊý×ÖÐͲÎÊý²¢·µ»ØÊýÖµÐ͵ÄÖµ¡£¶àÊý¸ÃÀຯÊýµÄ·µ»ØÖµÖ§³Ö38λСÊýµã£¬ÖîÈ磺COS, COSH, EXP, LN, LOG,
SIN, SINH, SQRT, TAN, and TANH Ö ......