[求助] start with connect by 奇怪的問題
Oracle 10.2.0.5 64bit . 測試資料庫, 期間沒有任何資料增加及刪除 。
以下SQL 在toad中執行顯示出來的結果為 18 筆 (備註: 單獨執行藍色部分為213筆) 。
SELECT a.ID, a.parent_id, a.name_en, a.name_zh_tw, a.name_zh_cn,
a.seq, a.TYPE,
a.description
FROM
(SELECT DISTINCT ID, app_id, parent_id, seq, name_en, name_zh_tw,
name_zh_cn, TYPE, description, action
FROM (SELECT a.*
FROM pf_access_node a
WHERE a.active_flag = '1'
AND a.app_id =
'159CBB0D0AA1237700A61D644DF26DC0'
START WITH ( EXISTS (
SELECT *
FROM pf_role_user b,
pf_role c,
pf_role_access d
WHERE c.active_flag = '1'
AND b.role_id = c.ID
AND c.ID = d.role_id
AND b.user_id =
'EE95B4040AB5132B00F449B85F0F18B4'
AND d.access_node_id = a.ID)
OR EXISTS (
SELECT *
FROM pf_agent
WHERE active_flag = '1'
AND agent_type = 'FUNC'
AND agent_id =
'9EEF6CDA0A86825101AFF012F9B905C1'
AND ref_id = a.ID
AND NVL (start_date,
SYSDATE) <= SYSDATE
AND NVL (end_date, SYSDATE) >=
SYSDATE)
)
CONNECT BY PRIOR a.ID = a.parent_id
UNION
SELECT a.*
FROM pf_access_node a
WHERE a.active_flag = '1'
AND a.app_id =
'159CBB0D0AA1237700A61D644DF26DC0'
START WITH ( EXISTS (
SELECT *
FROM pf_role_user b,
pf_role c,
pf_role_access d
WHERE c.active_flag = '1'
AND b.role_id = c.ID
AND c.ID = d.role_id
AND b.user_id =
'EE95B4040AB5132B00F449B85F0F18B4'
AND d.access_node_id = a.ID)
OR EXISTS (
SELECT *
FROM pf_agent
WHERE active_flag = '1'
AND agent_type = 'FUNC'
AND agent_id =
'9EEF6CDA0A86825101AFF012F9B905C1'
AND ref_id = a.ID
AND NVL (start_date,
SYSDATE) <= SYSDATE
AND NVL (end_date, SYSDATE) >=
SYSDATE)
)
CONNECT BY PRIOR a.parent_id = a.ID)
ORDER BY parent_id, seq) a
WHERE 1 = 1
START WITH a.parent_id IS NULL
CONNECT BY PRIOR a.ID = a.parent_id
使用create table test as xxxx ; 方式將藍色部分值匯入到一個測試表test 。
然後使用如下語句將上面藍色部分替代為 test , 結果查詢出來的結果為 213 筆 。
SELECT a.ID, a.parent_id, a.name_en, a.name_zh_tw, a.name_zh_cn,
a.seq, a.TYPE,
a.description
FROM
(test) a
WHERE 1 = 1
START WITH a.parent_id IS NULL
CONNECT BY PRIOR a.ID = a.parent_id
結果要同事幫忙匯入到9i 測試庫, 發現不管怎麼搞,結果都是一樣的, 213 筆 ,正確的。
[ 本帖最後由 tolywang 於 2010-12-23 09:13 編輯 ]
以下SQL 在toad中執行顯示出來的結果為 18 筆 (備註: 單獨執行藍色部分為213筆) 。
SELECT a.ID, a.parent_id, a.name_en, a.name_zh_tw, a.name_zh_cn,
a.seq, a.TYPE,
a.description
FROM
(SELECT DISTINCT ID, app_id, parent_id, seq, name_en, name_zh_tw,
name_zh_cn, TYPE, description, action
FROM (SELECT a.*
FROM pf_access_node a
WHERE a.active_flag = '1'
AND a.app_id =
'159CBB0D0AA1237700A61D644DF26DC0'
START WITH ( EXISTS (
SELECT *
FROM pf_role_user b,
pf_role c,
pf_role_access d
WHERE c.active_flag = '1'
AND b.role_id = c.ID
AND c.ID = d.role_id
AND b.user_id =
'EE95B4040AB5132B00F449B85F0F18B4'
AND d.access_node_id = a.ID)
OR EXISTS (
SELECT *
FROM pf_agent
WHERE active_flag = '1'
AND agent_type = 'FUNC'
AND agent_id =
'9EEF6CDA0A86825101AFF012F9B905C1'
AND ref_id = a.ID
AND NVL (start_date,
SYSDATE) <= SYSDATE
AND NVL (end_date, SYSDATE) >=
SYSDATE)
)
CONNECT BY PRIOR a.ID = a.parent_id
UNION
SELECT a.*
FROM pf_access_node a
WHERE a.active_flag = '1'
AND a.app_id =
'159CBB0D0AA1237700A61D644DF26DC0'
START WITH ( EXISTS (
SELECT *
FROM pf_role_user b,
pf_role c,
pf_role_access d
WHERE c.active_flag = '1'
AND b.role_id = c.ID
AND c.ID = d.role_id
AND b.user_id =
'EE95B4040AB5132B00F449B85F0F18B4'
AND d.access_node_id = a.ID)
OR EXISTS (
SELECT *
FROM pf_agent
WHERE active_flag = '1'
AND agent_type = 'FUNC'
AND agent_id =
'9EEF6CDA0A86825101AFF012F9B905C1'
AND ref_id = a.ID
AND NVL (start_date,
SYSDATE) <= SYSDATE
AND NVL (end_date, SYSDATE) >=
SYSDATE)
)
CONNECT BY PRIOR a.parent_id = a.ID)
ORDER BY parent_id, seq) a
WHERE 1 = 1
START WITH a.parent_id IS NULL
CONNECT BY PRIOR a.ID = a.parent_id
使用create table test as xxxx ; 方式將藍色部分值匯入到一個測試表test 。
然後使用如下語句將上面藍色部分替代為 test , 結果查詢出來的結果為 213 筆 。
SELECT a.ID, a.parent_id, a.name_en, a.name_zh_tw, a.name_zh_cn,
a.seq, a.TYPE,
a.description
FROM
(test) a
WHERE 1 = 1
START WITH a.parent_id IS NULL
CONNECT BY PRIOR a.ID = a.parent_id
結果要同事幫忙匯入到9i 測試庫, 發現不管怎麼搞,結果都是一樣的, 213 筆 ,正確的。
[ 本帖最後由 tolywang 於 2010-12-23 09:13 編輯 ]
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/35489/viewspace-682501/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle start with connect by PostgreSQL recursive cteOracleSQL
- [轉載] Oracle:start with...connect by子句的用法Oracle
- go熱更新問題求助Go
- SAE安裝問題,求助
- Composer 使用遇到問題求助
- redis connect timeout問題排查Redis
- JavaScript 中的一些奇怪問題JavaScript
- [20211210]優化遇到的奇怪問題.txt優化
- j2me rms 的奇怪問題
- [20180417]奇怪的grep過濾問題.txt
- 迴歸測試遇到的問題求助
- [20220811]奇怪的隱式轉換問題.txt
- 兩個看似奇怪的MySQL語句問題MySql
- python 詭異問題求助各位大哥Python
- 上線後遇到一個很奇怪的問題
- 一次奇怪的StackOverflowError問題查詢之旅Error
- 奇怪的OGG問題:DBLOGREADER mode: (308) ORA-00308
- cannot read prpperty ‘start‘ of undefined(問題記錄)Undefined
- [提問交流]關於Jquery Append鉤子的問題,大神求助!jQueryAPP
- playwright 中使用 xpath 定位元素遇到的奇怪問題
- **【求助】關於抽樣和標準化的問題**
- 【Linux】curl: (35) SSL connect error問題處理LinuxError
- python pip安裝 setuptools相關的一些奇怪問題Python
- WPF App後臺檔案彈窗導致奇怪的問題APP
- 【Go語言探險】線上奇怪日誌問題的排查Go
- [提問交流]【小白求助】onethink後臺檔案上傳問題
- 上手MySQL之解決問題:not allowed to connect to this MySQL serverMySqlServer
- 【求助各位大佬】【急】pytest 動態引數化遇到的問題
- 奇怪的漢諾塔 - 題解
- 解決new Thread().Start導致高併發CPU 100%的問題thread
- 求助!關於npm install 老是出現這個問題NPM
- 求助 | 天氣預報資料採集,更新入庫的問題!
- 解決telnet: connect to address 127.0.0.1: Connection refused的錯誤資訊問題127.0.0.1
- 使用mysql-connect-java-8.0.11驅動包需要注意的問題MySqlJava
- 關於解決Server Tomcat v9.0 Server at localhost failed to start的問題ServerTomcatlocalhostAI
- 記一次奇怪的檔案控制程式碼洩露問題
- 關於Anaconda3打不開Anaconda Navigator和Spyder的奇怪問題
- 關於Quartus的start按鈕灰色無法下載的問題的解決
- Oracle優化案例-定位start with connect by遞迴死迴圈資料(二十二)Oracle優化遞迴