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 by子句的用法Oracle
- PostgreSQL Oracle 相容性 - connect by 2SQLOracle
- PostgreSQL DBA(35) - CTESQL
- PostgreSQL中索引與CTE簡介SQL索引
- Oracle優化案例-定位start with connect by遞迴死迴圈資料(二十二)Oracle優化遞迴
- Laravel connect oracleLaravelOracle
- AUTO START ORACLE ON LINUX(zt)OracleLinux
- Linux Use ODBC Connect OracleLinuxOracle
- PostgreSQL用CTE語法+繼承實現拆分大表SQL繼承
- PostgreSQL pg_ctl start超時分析SQL
- Oracle Database Cloud - Database as a Service Quick StartOracleDatabaseCloudUI
- Oracle的SYS_CONNECT_BY_PATH函式Oracle函式
- oracle語法相容--如何透過with recursive語法來實現oracle的分層查詢Oracle
- Oracle vs PostgreSQL DBA(21)- Oracle VPDOracleSQL
- Recursive Algorithm for Sliding Signal ProcessingGo
- Postgresql實戰:使用pg_basebackup或pg_start_backup方式搭建Postgresql主從流複製SQL
- Oracle vs PostgreSQL DBA(22)- Oracle VPD#2OracleSQL
- 遞迴轉非遞迴 棧模擬 Recursive to Non-recursive stack simulated 總結遞迴
- PostgreSQL/Oracle 時間改成秒SQLOracle
- Oracle vs PostgreSQL Develop(17) - ARRAYOracleSQLdev
- Oracle vs PostgreSQL Develop(15) - DISTINCT ONOracleSQLdev
- Oracle vs PostgreSQL Develop(18) - BooleanOracleSQLdevBoolean
- mysql with as 公用表表示式(CTE)MySql
- T-SQL:CTE用法(十)SQL
- Oracle案例09——ORA-12154: TNS:could not resolve the connect identifier specifiedOracleIDE
- PostgreSQL批量、單步寫入-row,statement觸發器(中間表)、CTE幾種用法效能對比SQL觸發器
- 多表關聯更新(mysql,oracle,postgreSQL)MySqlOracle
- Oracle到PostgreSQL等價改寫OracleSQL
- Oracle vs PostgreSQL Develop(29) - COMMIT in PLSQLOracleSQLdevMIT
- Oracle vs PostgreSQL Develop(16) - Prepared StatementOracleSQLdev
- Oracle vs PostgreSQL Develop(20) - Materialized ViewOracleSQLdevZedView
- Oracle vs PostgreSQL Develop(19) - PIPE ROWOracleSQLdev
- PostgreSQL與Oracle的sql差異SQLOracle
- Oracle vs PostgreSQL Develop(28) - function overloadOracleSQLdevFunction
- Oracle vs PostgreSQL Develop(26) - ASCII 0OracleSQLdevASCII
- Oracle與PostgreSQL比較:PostgreSQL至少在安裝和大小方面擊敗了Oracle - foersterOracleSQL
- 引數fast_start_parallel_rollback調整oracle回滾的速度ASTParallelOracle
- LightDB/PostgreSQL 相容Oracle儲存過程SQLOracle儲存過程