¶ÔÓÚoracle½øÐмòµ¥Ê÷²éѯ(µÝ¹é²éѯ)_OracleÊý¾Ý¿â_ºÚ¿Í·ÀÏßÍø°²·þÎñÆ÷ά»¤»ùµØ--Powered by WWW.RONGSEN.COM.CN

¶ÔÓÚoracle½øÐмòµ¥Ê÷²éѯ(µÝ¹é²éѯ)

×÷ÕߣººÚ¿Í·ÀÏßÍø°²Oracleά»¤»ùµØ À´Ô´£ººÚ¿Í·ÀÏßÍø°²Oracleά»¤»ùµØ ä¯ÀÀ´ÎÊý£º0

±¾Æª¹Ø¼ü´Ê£ºOracleÊý¾Ý¿âOracleÊý¾Ý¿â
ºÚ¿Í·ÀÏßÍø°²ÍøѶ£ºDEPTID PAREDEPTID NAME NUMBER NUMBER CHAR (40 Byte) ²¿ÃÅid ¸¸²¿ÃÅid(ËùÊô²¿ÃÅid) ²¿ÃÅÃû³Æ Í¨¹ý×Ó½ÚµãÏò¸ù½Úµã×·Ë·.Sql´úÂë select * from persons.dept start with deptid=76 connect ...

DEPTID PAREDEPTID NAME
NUMBER NUMBER CHAR (40 Byte)
²¿ÃÅid ¸¸²¿ÃÅid(ËùÊô²¿ÃÅid) ²¿ÃÅÃû³Æ

ͨ¹ý×Ó½ÚµãÏò¸ù½Úµã×·Ë·.

Sql´úÂë
select * from persons.dept start with deptid=76 connect by prior paredeptid=deptid   
 select * from persons.dept start with deptid=76 connect by prior paredeptid=deptid  

ͨ¹ý¸ù½Úµã±éÀú×Ó½Úµã.

Sql´úÂë
select * from persons.dept start with paredeptid=0 connect by prior deptid=paredeptid   
select * from persons.dept start with paredeptid=0 connect by prior deptid=paredeptid  

¿Éͨ¹ýlevel ¹Ø¼ü×Ö²éѯËùÔÚ²ã´Î.

Sql´úÂë
select a.*,level from persons.dept a start with paredeptid=0 connect by prior deptid=paredeptid   
select a.*,level from persons.dept a start with paredeptid=0 connect by prior deptid=paredeptid

Ôٴθ´Ï°Ò»ÏÂ:start with ...connect by µÄÓ÷¨£¬ start with ºóÃæËù¸úµÄ¾ÍÊǾÍÊǵݹéµÄÖÖ×Ó¡£

µÝ¹éµÄÖÖ×ÓÒ²¾ÍÊǵݹ鿪ʼµÄµØ·½ connect by ºóÃæµÄ"prior" Èç¹ûȱʡ£ºÔòÖ»Äܲéѯµ½·ûºÏÌõ¼þµÄÆðʼÐУ¬²¢²»½øÐеݹé²éѯ£»

connect by prior ºóÃæËù·ÅµÄ×Ö¶ÎÊÇÓйØϵµÄ£¬ËüÖ¸Ã÷Á˲éѯµÄ·½Ïò¡£

Á·Ï°£º ͨ¹ý×Ó½Úµã»ñµÃ¶¥½Úµã

Sql´úÂë

select FIRST_VALUE(deptid) OVER (ORDER BY LEVEL DESC ROWS UNBOUNDED PRECEDING) AS firstdeptid from persons.dept start with deptid=76 connect by prior paredeptid=deptid  

    ºÚ¿Í·ÀÏßÍø°²·þÎñÆ÷ά»¤·½°¸±¾ÆªÁ¬½Ó£ºhttp://www.rongsen.com.cn/show-12065-1.html
Íøվά»¤½Ì³Ì¸üÐÂʱ¼ä:2012-03-23 00:29:41  ¡¾´òÓ¡´ËÒ³¡¿  ¡¾¹Ø±Õ¡¿
ÎÒÒªÉêÇë±¾Õ¾£ºNµã | ºÚ¿Í·ÀÏß¹ÙÍø |  
רҵ·þÎñÆ÷ά»¤¼°Íøվά»¤ÊÖ¹¤°²È«´î½¨»·¾³£¬ÍøÕ¾°²È«¼Ó¹Ì·þÎñ¡£ºÚ¿Í·ÀÏßÍø°²·þÎñÆ÷ά»¤»ùµØÕÐÉ̽øÐÐÖУ¡QQ:29769479

footer  footer  footer  footer