oracleÖÐconnect by priorʵÏֵݹé²éѯ
oracleÖÐconnect by priorʵÏֵݹé²éѯ
ÊÕ¼¯µÄ¼¸ÌõÔÚoracleÖÐͨ¹ýconnect by priorÀ´ÊµÏֵݹé²éѯ
Start with...Connect By×Ó¾äµÝ¹é²éѯһ°ãÓÃÓÚÒ»¸ö±íά»¤Ê÷ÐνṹµÄÓ¦Óá£
´´½¨Ê¾Àý±í£º
CREATE TABLE TBL_TEST
(
ID NUMBER,
NAME VARCHAR2(100 BYTE),
PID NUMBER DEFAULT 0
);
²åÈë²âÊÔÊý¾Ý£º
INSERT INTO TBL_TEST(ID,NAME,PID) VALUES('1','10','0');
INSERT INTO TBL_TEST(ID,NAME,PID) VALUES('2','11','1');
INSERT INTO TBL_TEST(ID,NAME,PID) VALUES('3','20','0');
INSERT INTO TBL_TEST(ID,NAME,PID) VALUES('4','12','1');
INSERT INTO TBL_TEST(ID,NAME,PID) VALUES('5','121','2');
´ÓRootÍùÊ÷Ä©Éҵݹé
select * from TBL_TEST
start with id=1
connect by prior id = pid
´ÓÄ©ÉÒÍùÊ÷ROOTµÝ¹é
select * from TBL_TEST
start with id=5
connect by prior pid = id
===============================================================================================================
ÓÐÒ»Õűí t
×ֶΣº
parent
child
Á½¸ö×ֶεĹØϵÊǸ¸×Ó¹Øϵ
дһ¸ösqlÓï¾ä£¬²éѯ³öÖ¸¶¨¸¸ÏÂÃæµÄËùÓеÄ×Ó
±ÈÈç
a b
a c
a e
b b1
b b2
c c1
e e1
e e3
d d1
Ö¸¶¨parent=a£¬Ñ¡³ö
a b
a c
a e
b b1
b b2
c c1
e e1
e e3
SQLÓï¾ä£º
select pare
Ïà¹ØÎĵµ£º
¿ª·¢Êý¾Ý¿âÓ¦Óã¬Ñ¡ÔñÒ»¸öºÃµÄÊý¾Ý¿âÊǷdz£ÖØÒªµÄ¡£±¾ÎÄ´ÓһЩ·½Ãæ±È½ÏÁËSQL ServerÓëOracle¡¢DB2ÈýÖÖÊý¾Ý¿â£¬ÎªÄãÑ¡ÔñÊý¾Ý¿âÌṩһЩ²Î¿¼¡£
¡¡¡¡
¡¡¡¡¿ª·ÅÐÔ
¡¡¡¡SQL Server
¡¡¡¡Ö»ÄÜÔÚWindows ÉÏÔËÐУ¬Ã»ÓÐË¿ºÁµÄ¿ª·ÅÐÔ£¬²Ù×÷ϵͳµÄϵͳµÄÎȶ¨¶ÔÊý¾Ý¿âÊÇÊ®·ÖÖØÒªµÄ¡£Windows9XϵÁвúÆ·ÊÇÆ«ÖØÓÚ×ÀÃæÓ¦Óã¬NT se ......
SQLÖеĵ¥¼Ç¼º¯Êý
1.ASCII
·µ»ØÓëÖ¸¶¨µÄ×Ö·û¶ÔÓ¦µÄÊ®½øÖÆÊý;
SQL> select ascii(A) A,ascii(a) a,ascii(0) zero,ascii( ) space from dual;
A A ZERO SPACE
--------- --------- --------- ---------
65 97 48 32
2.CHR
¸ø³öÕûÊý,·µ»Ø¶ÔÓ¦µÄ×Ö·û;
SQL> select chr(54740) zhao,chr(65) chr65 from d ......
INTÀàÐÍÊÇNUMBERÀàÐ͵Ä×ÓÀàÐÍ¡£
ÏÂÃæ¼òҪ˵Ã÷£º
£¨1£©NUMBER£¨P,S£©
¸ÃÊý¾ÝÀàÐÍÓÃÓÚ¶¨ÒåÊý×ÖÀàÐ͵ÄÊý¾Ý£¬ÆäÖÐP±íʾÊý×ÖµÄ×ÜλÊý£¨×î´ó×Ö½Ú¸öÊý£©£¬¶øSÔò±íʾСÊýµãºóÃæµÄλÊý¡£¼ÙÉ趨ÒåSALÁÐΪNUMBER£¨6,2£©ÔòÕûÊý×î´óλÊýΪ4루6-2=4£©£¬¶øСÊý×î´óλÊýΪ2λ¡£
£¨2£©INTÀàÐÍ
µ±¶¨ÒåÕûÊýÀàÐÍʱ£¬¿ÉÒÔÖ±½ÓʹÓÃNU ......
×¢£ºÏÂÃæÖ»ÊÇÎÒ´ÖÁӵļǼһÏ£¬×Ô¼ºÔÚ¿ª·¢ÖÐËùѧµÄÒ»²¿·Ö×ÊÁÏ£¡
1£® µÚÒ»¡¢ÊÇÏÂÔØÒ»¸ö“Oracle9i¿Í»§¶Ë¾«¼ò°æ.exe”¿Í»§¶Ë£¬È»ºó°ÑËü°²×°µ½CÅÌÏÂÃæ¡£
È»ºó°ÑÎÒÃÇ×Ô¼ºÅäÖúõĔ tnsnames.ora”Îļþ£¬¸´¸ÇC:\oracle\ora90\network\adminÏÂÃæµÄtnsnames.oraÎļþ¡£
2£® ÔÚVS2005¿ª·¢¹¤¾ßÖ ......
±¾ÎIJ¢²»×¼±¸½éÉÜÈ«²¿µÄoracleº¯Êý£¬µ±Ç°ÇéÊÆÏ£¬°³Ò²»¹Ã»Õâ¸öʱ¼ä£¬ÐèҪѧϰµÄ¶«Î÷Ì«¶àÁË£¬Òª°Ñ¶àÊýʱ¼ä»¨ÔÚѧϰ¾³£ÄÜÓÃÉϵļ¼Êõ·½Ãæ:)£¬ËùÒÔÈç¹ûÊÇ×¼±¸ÉîÈëÁ˽âËùÓÐoracleº¯ÊýµÄÅóÓÑ£¬»¹ÊÇÈ¥¹Ø×¢£ºOracle SQL Reference¹Ù·½Îĵµ¸ü¿¿Æ×һЩ¡£
¡¡¡¡±¾Îĸü¶à½«»á½éÉÜÈý˼ÔÚÈÕ³£Öо³£»áÓõ½µÄ ......