kevinxi的gravatar头像
kevinxi 2014-05-19 00:27:43

oracle与DB2递归查询sql语句

DB2 通过WITH AS递归查询

WITH TA (ORG_ID, ORG_NAME, PARENT_ORG_ID)

        AS (SELECT ORG_ID, ORG_NAME, PARENT_ORG_ID

              FROM TM_ORG

             WHERE org_ID = 1

            UNION ALL

            SELECT B.ORG_ID, B.ORG_NAME, B.PARENT_ORG_ID

              FROM TM_ORG B, <span style="color: #ff0000;">TA A</span>

             WHERE B.PARENT_ORG_ID = A.org_id)

SELECT ORG_ID, ORG_NAME, PARENT_ORG_ID

  FROM TA

oracle 通过 start with connect by prior 递归查询

select * from TM_ORG start with org_id = 1 connect by prior org_id = PARENT_ORG_ID;

打赏

顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友