Oracle SQL的遞迴查詢

mengzhaoliang發表於2009-05-25

Oracle  SQL的遞迴查詢:
1、表機構
SQL> desc comm_org_subjection
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 ORG_SUBJECTION_ID                         NOT NULL VARCHAR2(32)    子鍵
 ORG_ID                                    NOT NULL VARCHAR2(32)
 FATHER_ORG_ID                             NOT NULL VARCHAR2(32)         父鍵
 LOCKED_IF                                 NOT NULL VARCHAR2(1)
 START_DATE                                NOT NULL DATE
 END_DATE                                           DATE
 EDITION_NAMEPLATE                                  NUMBER(8)
 CODE_AFFORD_IF                                     VARCHAR2(1)
 CODE_AFFORD_ORG_ID                        NOT NULL VARCHAR2(32)
 CODING_SHOW_ID                                     NUMBER(8)
 BSFLAG                                             VARCHAR2(1)
 MODIFI_DATE                                        DATE
 CREATOR_ID                                         VARCHAR2(32)
 CREATE_DATE                                        DATE
 CREATOR                                            VARCHAR2(35)


2、遞迴查詢父結點 org_id為C6000000000001下的所有子結點:
select * from comm_org_subjection a
start with a.org_id='C6000000000001'
connect by prior a.org_subjection_id=a.father_org_id


3、遞迴查詢子結點 org_id為C6000000000001下的所有父結點:
select org_id from comm_org_subjection a
start with a.org_id='C6000000000001'
connect by prior a.father_org_id=a.org_subjection_id

 


 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12778571/viewspace-604129/,如需轉載,請註明出處,否則將追究法律責任。

相關文章