Oracle start with ... connect by prior Ó÷¨
Óï·¨£º
select *
from ±íÃû
where Ìõ¼þ1
start with Ìõ¼þ2
connect by prior µ±Ç°±í×Ö¶Î=¼¶Áª±í×Ö¶Î
start withÓëconnect by priorÓï¾äÍê³ÉµÝ¹é¼Ç¼£¬ÐγÉÒ»¿ÃÊ÷Ðνṹ£¬Í¨³£¿ÉÒÔÔÚ¾ßÓвã´Î½á¹¹µÄ±íÖÐʹÓá£
start with±íʾ¿ªÊ¼µÄ¼Ç¼
connect by prior Ö¸¶¨Ó뵱ǰ¼Ç¼¹ØÁªÊ±µÄ×ֶιØÏµ
´úÂ룺
--´´½¨²¿ÃÅ±í£¬ÕâÊÇÒ»¸ö¾ßÓвã´Î½á¹¹µÄ±í£¬×ӼǼͨ¹ýparent_idÓ븸¼Ç¼µÄid½øÐйØÁª
create table DEPT(
ID NUMBER(9) PRIMARY KEY, --²¿ÃÅID
NAME VARCHAR2(100), --²¿ÃÅÃû³Æ
PARENT_ID NUMBER(9) --¸¸¼¶²¿ÃÅID£¬Í¨¹ý´Ë×Ö¶ÎÓëÉϼ¶²¿ÃŹØÁª
);
Ïò±íÖвåÈëÈçÏÂÊý¾Ý£¬ÎªÁËʹ´úÂë¼òµ¥£¬Ò»¸ö²¿ÃŽö¾ßÓÐÒ»¸öϼ¶²¿ÃÅ
¡ñ´Ó¸ù½Úµã¿ªÊ¼²éѯµÝ¹éµÄ¼Ç¼
select *
from dept
start with id=1
connect by prior id = parent_id;
ÏÂÃæÊDzéѯ½á¹û£¬start with id=1±íʾ´Óid=1µÄ¼Ç¼¿ªÊ¼²éѯ£¬ÏòÒ¶×ӵķ½ÏòµÝ¹é£¬µÝ¹éÌõ¼þÊÇid=parent_id£¬µ±Ç°¼Ç¼µÄidµÈÓÚ×ӼǼµÄparent_id
¡ñ´ÓÒ¶×ӽڵ㿪ʼ²éѯµÝ¹éµÄ¼Ç¼
select *
from dept
start with id=5
connect by prior parent_id = id;
ÏÂÃæÊDzéѯ½á¹û£¬µÝ¹éÌõ¼þ°´ÕÕµ±Ç°¼Ç¼µÄparent_idµÈÓ븸¼Ç¼µÄid
¡ñ¶Ô²éѯ½á¹û¹ýÂË
select *
from dept
where name like '%ÏúÊÛ%'
start with id=1
connect by prior id = parent_id;
ÔÚÏÂÃæµÄ²éѯ½á¹ûÖпÉÒÔ¿´µ½£¬Ê×ÏÈʹÓÃstart with... connect by prior²éѯ³öÊ÷ÐεĽṹ£¬È»ºówhereÌõ¼þ²ÅÉúЧ£¬¶ÔÈ«²¿²éѯ½á¹û½øÐйýÂË
¡ñpriorµÄ×÷ÓÃ
prior¹Ø¼ü×Ö±íʾ²»½øÐеݹé²éѯ£¬½ö²éѯ³öÂú×ãid=1µÄ¼Ç¼£¬ÏÂÃæÊǽ«µÚÒ»¸ö²éѯȥµôprior¹Ø¼ü×Öºó½á¹û
select *
from dept
start with id=1
connect by prior id = parent_id;
Ïà¹ØÎĵµ£º
ΪÁËÑо¿Ò»ÏÂϵͳÔÚºǫ́¶¼¸ÉÁËʲô£¬µ±È»ÊÇÎÒÔÚ´úÂëÀïûÕÒµ½µÄÇé¿öÏ£¬Ñо¿ÁËÒ»ÏÂtrace£¬½á¹ûÓÐÒ»¶¨µÄ°ïÖú¡£oracleÖв»Ïñsql serverÖÐÄÇÑùÖ±½ÓÌṩͼÏñ»¯µÄ¹¤¾ß£¬ËùÒÔ»¹ÊǵÃ×Ô¼º¶¯ÊÖÀ´×ö£¬¹éÄÉÁËһϣ¬²½ÖèÈçÏ£º
²éѯsession£º
SQL> select sid, serial#, username from v$session where username='XXX';//ÕÒ³öÄãÒª¸ú ......
---------Êýѧº¯Êý
1.¾ø¶ÔÖµ
S:select abs(-1) value
O:select abs(-1) value from dual
2.È¡Õû(´ó)
S:select ceiling(-1.001) value
O:select ceil(-1.001) value from dual
3.È¡Õû£¨Ð¡£©
S:select floor(-1.001) value
O:select floor(-1.001) value from dual
4.È¡Õû£¨½ØÈ¡£©
S:select cast(-1.002 as int) v ......
--°ü
create or replace package pkg_query as
type cur_query is ref cursor;
end pkg_query;
--¹ý³Ì
CREATE OR REPLACE PROCEDURE "PRC_QUERY" (p_tableName
in varchar2, --±íÃû
& ......
ÔĶÁoracleÎĵµµÄb10743£¬¡¶conceps¡·¡£Õâ±¾±»oracle¹«Ë¾µÄ´óʦ¼¶µÄÈËÎïMichele CyranµÈÅ£ÈËËùд£¬ÕæÊÇÒ»±¾²»´íµÄÊé¼®¡£¿É̾ӢÎIJ»Ì«ºÃ£¬µ«Å¬Á¦£¬×Ü»áÓÐÊÕ»ñµÄ¡£»¹ÊÇ´ÓËûµÄÊý¾Ý¼Ü¹¹À´Ëµ°É£¡
£¨Ò»£©Data blocks £¬Extents£¬Segment
Õâ¾ÍÊÇËûÃÇÖ®¼äµÄÂß¼½á¹¹¡£
ÏÈ¿´Data blo ......
1 ¾Û¼¯(cluster)
1.1 ¸ÅÄ
ÓÃÓÚ½«²»Í¬±íÖеÄÊý¾Ý´æ´¢µ½ÏàͬµÄÎïÀíÊý¾Ý¿éÖУ¬ÓÃÓÚ¶à±íÊý¾ÝÐèҪƵ·±½øÐÐÁªºÏ²éѯµÄÇé¿öÏ¡£¶à±íÊý¾Ý´æ´¢ÔÚÏàͬÊý¾Ý¿éºó£¬ÔÚ¶Ô¶Ô±í½øÐÐÁªºÏ²éѯʱ£¬ËùÐè¶ÁÈ¡µÄÎïÀí¿éÊý¼õÉÙ£¬´Ó¶øÌá¸ß²éѯÐÔÄÜ¡£
ÐèҪעÒâµÄÊǶԾۼ¯Öе¥±íµÄ²éѯºÍ¶Ô¾Û¼¯ÖбíÊý¾Ý½øÐÐÐ޸Ļò²åÈëµÈÊÂÎñ²Ù×÷ʱ£¬ÐÔÄܽ«Ê ......