Oracle start with connect by PostgreSQL recursive cte
Oracle:
SELECT DISTINCT ID, PARENT_MODULE_CODE, MODULE_CODE, MODULE_NAME, LEAF_MARK, NODE_EXPAND, RAR_NAME_FORMAT, RAR_SUFFIX_FORMAT, REPORT_FILE_NAME_FORMAT, REPORT_FILE_SUFFIX_FORMAT, EXPORT_FILE_PATH, REPORT_SEND_TYPE, FILING_TYPE, FEED_BACK_DOC_PATH, FEED_BACK_DOC_NAME_FORMAT, FEED_BACK_DOC_SUFFIX_FORMAT, BUSINESS_REPORT_SQL, CREATE_TIME, UPDATE_TIME, CREATOR_NO, UPDATOR_NO, STATUS, REPORT_FILE_CODE, REPORT_RAR_CODE, GEN_REPORT_DATA_TYPE, GEN_REPORT_DATA_EXP, GEN_BDATA_DATASOURCE_ID, ENV_ID FROM URP_REPORT_MODULE t WHERE env_id = '001' START WITH status = 1 CONNECT BY PRIOR t.parent_module_code = t.module_code ORDER BY t.module_code ASC, t.module_name ASC;
PostgreSQL:
with recursive cte as ( select ID, PARENT_MODULE_CODE, MODULE_CODE, MODULE_NAME, LEAF_MARK, NODE_EXPAND, RAR_NAME_FORMAT, RAR_SUFFIX_FORMAT, REPORT_FILE_NAME_FORMAT, REPORT_FILE_SUFFIX_FORMAT, EXPORT_FILE_PATH, REPORT_SEND_TYPE, FILING_TYPE, FEED_BACK_DOC_PATH, FEED_BACK_DOC_NAME_FORMAT, FEED_BACK_DOC_SUFFIX_FORMAT, BUSINESS_REPORT_SQL, CREATE_TIME, UPDATE_TIME, CREATOR_NO, UPDATOR_NO, STATUS, REPORT_FILE_CODE, REPORT_RAR_CODE, GEN_REPORT_DATA_TYPE, GEN_REPORT_DATA_EXP, GEN_BDATA_DATASOURCE_ID, ENV_ID from URP_REPORT_MODULE where status = 1 union all select d.ID, d.PARENT_MODULE_CODE, d.MODULE_CODE, d.MODULE_NAME, d.LEAF_MARK, d.NODE_EXPAND, d.RAR_NAME_FORMAT, d.RAR_SUFFIX_FORMAT, d.REPORT_FILE_NAME_FORMAT, d.REPORT_FILE_SUFFIX_FORMAT, d.EXPORT_FILE_PATH, d.REPORT_SEND_TYPE, d.FILING_TYPE, d.FEED_BACK_DOC_PATH, d.FEED_BACK_DOC_NAME_FORMAT, d.FEED_BACK_DOC_SUFFIX_FORMAT, d.BUSINESS_REPORT_SQL, d.CREATE_TIME, d.UPDATE_TIME, d.CREATOR_NO, d.UPDATOR_NO, d.STATUS, d.REPORT_FILE_CODE, d.REPORT_RAR_CODE, d.GEN_REPORT_DATA_TYPE, d.GEN_REPORT_DATA_EXP, d.GEN_BDATA_DATASOURCE_ID, d.ENV_ID from URP_REPORT_MODULE d join cte on cte.parent_module_code = d.module_code ) select distinct ID, PARENT_MODULE_CODE, MODULE_CODE, MODULE_NAME, LEAF_MARK, NODE_EXPAND, RAR_NAME_FORMAT, RAR_SUFFIX_FORMAT, REPORT_FILE_NAME_FORMAT, REPORT_FILE_SUFFIX_FORMAT, EXPORT_FILE_PATH, REPORT_SEND_TYPE, FILING_TYPE, FEED_BACK_DOC_PATH, FEED_BACK_DOC_NAME_FORMAT, FEED_BACK_DOC_SUFFIX_FORMAT, BUSINESS_REPORT_SQL, CREATE_TIME, UPDATE_TIME, CREATOR_NO, UPDATOR_NO, STATUS, REPORT_FILE_CODE, REPORT_RAR_CODE, GEN_REPORT_DATA_TYPE, GEN_REPORT_DATA_EXP, GEN_BDATA_DATASOURCE_ID, ENV_ID from cte order by cte.module_code asc, cte.module_name asc;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29990276/viewspace-2910359/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle Start with ....Connect ByOracle
- START WITH and CONNECT BY in Oracle SQLOracleSQL
- oracle中start with connect by priorOracle
- PostgreSQL DBA(35) - CTESQL
- start with ... connect by
- Oracle 樹操作(select…start with…connect by…prior)Oracle
- start with connect by prior
- start with connect by 用法
- START WITH...CONNECT BY
- [轉載] Oracle:start with...connect by子句的用法Oracle
- Oracle中start with...connect by prior子句用法.docOracle
- connect by..start with..
- start with ...connect by --轉載
- PostgreSQL Oracle 相容性 - connect by 2SQLOracle
- PostgreSQL中索引與CTE簡介SQL索引
- start with...connect by prior用法
- connect by ...[prior]...start with 學習
- start with ... connect by用法簡介
- 請教start with ......connect by prior .....用法
- Oracle 樹查詢 效能最佳化紀實(start with, connect by)Oracle
- [轉載]使用Oracle樹形查詢應注意 - Start with / Connect byOracle
- ORACLE 樹形查詢(connect by...start with...)的應用(三)Oracle
- ORACLE 樹形查詢(connect by...start with...)的應用(一)Oracle
- 分析函式connect by | start with學習函式
- [求助] start with connect by 奇怪的問題
- START WITH...CONNECT BY PRIOR簡單使用
- 樹型結構start with..........connect by prior
- PostgreSQL用CTE語法+繼承實現拆分大表SQL繼承
- PostgreSQL pg_ctl start超時分析SQL
- PostgreSQL用CTE語法+繼承實現平滑拆分大表SQL繼承
- Oracle優化案例-定位start with connect by遞迴死迴圈資料(二十二)Oracle優化遞迴
- Oracle connect byOracle
- 【--SQL基礎-->層次化查詢(START BY ... CONNECT BY PRIOR)】SQL
- WITH AS 用法-CTE
- linux start oracleLinuxOracle
- 【SQL 學習】層次化查詢之CONNECT BY 和 START WITHSQL
- Laravel connect oracleLaravelOracle
- Oracle “CONNECT BY” 使用Oracle