2014-02-18 42 views
0

我想測試一個查詢並得到ORA-00907錯誤。我相信這個錯誤是由於我用於RUN.RN_RUN_ID的內部查詢。
內部查詢本身工作正常,我給內部查詢的結果,外部查詢工作正常。任何洞察我做錯了什麼,將不勝感激。ORDER BY與內部查詢,給ORA-00907缺少右括號

Select 
    RELEASES.REL_NAME AS RELEASE_NAME, 
    RELEASE_CYCLES.RCYC_NAME AS CYCLE_NAME, 
    TESTCYCL.TC_TESTCYCL_ID AS TEST_INSTANCE_ID, 
    TEST.TS_NAME AS TEST_CASE_NAME, 
    TEST.TS_USER_26 AS TEST_POST_CONDITIONS, 
    TEST.TS_USER_25 AS TEST_PRE_CONDITIONS, 
    TEST.TS_TEST_ID AS TEST_CASE_ID, 
    TEST.TS_DESCRIPTION AS TEST_CASE_DESCRIPTION, 
    TESTCYCL.TC_STATUS AS TEST_ACTUAL_RESULTS, 
    TEST.TS_DEV_COMMENTS AS TEST_CASE_COMMENTS, 
    TEST.TS_RESPONSIBLE AS TEST_CASE_AUTHOR, 
    TEST.TS_CREATION_DATE AS TEST_CASE_CREATION_DATE, 
    TESTCYCL.TC_EXEC_DATE AS EXECUTION_DATE, 
    TESTCYCL.TC_EXEC_TIME AS EXECUTION_TIME, 
    TESTCYCL.TC_ACTUAL_TESTER AS EXECUTED_BY, 
    STEP.ST_ID AS STEP_ID, 
    STEP.ST_STEP_NAME AS STEP_NUMBER, 
    STEP.ST_DESCRIPTION AS STEP_DESCRIPTION, 
    STEP.ST_EXPECTED AS EXPECTED_RESULTS, 
    STEP.ST_ACTUAL AS ACTUAL_RESULTS, 
    STEP.ST_USER_07 AS STEP_COMMENT, 
    STEP.ST_STATUS AS STEP_STATUS, 
    STEP.ST_STEP_ORDER AS STEP_ORDER, 
    STEP.ST_USER_01 AS STEP_TYPE, 
    RUN.RN_RUN_ID AS RUN_ID From ((((((RELEASES JOIN RELEASE_CYCLES 
    ON RELEASES.REL_ID = RELEASE_CYCLES.RCYC_PARENT_ID 
    AND RELEASES.REL_NAME = 'XYZ') LEFT JOIN CYCLE 
    ON RELEASE_CYCLES.RCYC_ID = CYCLE.CY_ASSIGN_RCYC) LEFT JOIN TESTCYCL 
    ON CYCLE.CY_CYCLE_ID = TESTCYCL.TC_CYCLE_ID) LEFT JOIN RUN 
    ON TESTCYCL.TC_TESTCYCL_ID = RUN.RN_TESTCYCL_ID) LEFT JOIN TEST 
    ON TESTCYCL.TC_TEST_ID = TEST.TS_TEST_ID) LEFT JOIN STEP 
    ON RUN.RN_RUN_ID = STEP.ST_RUN_ID) WHERE (TEST.TS_TYPE = 'MANUAL' OR 
    TEST.TS_TYPE = 'QUICKTEST_TEST' OR TEST.TS_TYPE = 'LR-SCENARIO') 
    AND RUN.RN_RUN_ID in(Select max(RUN.RN_RUN_ID) From (((((((RELEASES JOIN RELEASE_CYCLES 
    ON RELEASES.REL_ID = RELEASE_CYCLES.RCYC_PARENT_ID AND RELEASES.REL_NAME = 'XYZ') 
    LEFT JOIN CYCLE ON RELEASE_CYCLES.RCYC_ID = CYCLE.CY_ASSIGN_RCYC) 
    LEFT JOIN TESTCYCL ON CYCLE.CY_CYCLE_ID = TESTCYCL.TC_CYCLE_ID) 
    LEFT JOIN RUN ON TESTCYCL.TC_TESTCYCL_ID = RUN.RN_TESTCYCL_ID) 
    LEFT JOIN TEST ON TESTCYCL.TC_TEST_ID = TEST.TS_TEST_ID) 
    LEFT JOIN STEP ON RUN.RN_RUN_ID = STEP.ST_RUN_ID) 
    LEFT JOIN LINK ON STEP.ST_ID = LINK.LN_ENTITY_ID AND LINK.LN_ENTITY_TYPE = 'STEP') 
    WHERE (TEST.TS_TYPE = 'MANUAL' OR TEST.TS_TYPE = 'QUICKTEST_TEST' OR 
    TEST.TS_TYPE = 'LR-SCENARIO')AND TEST.TS_TEST_ID =145965 
    ORDER BY TESTCYCL.TC_TESTCYCL_ID) 
    ORDER BY TESTCYCL.TC_TESTCYCL_ID,STEP.ST_STEP_ORDER 
+0

左括號太多! (((((((RELEASES' –

+0

添加一個結尾括號 – SilverlightFox

+1

我們不是人工編譯器,去掉你的查詢並遞增地返回 – OldProgrammer

回答

3

編碼風格和不必要的嵌套括號使這真的很難閱讀和解釋。但它也有幫助,與一些評論相反,ORA-00907並不總是意味着括號的數量不統一,而是可能表明更常見的語法錯誤導致解析器退出。在這種情況下,它不是很有幫助。

的問題是order by子句倒數第二行,你對與in比較子查詢中:

... 
AND RUN.RN_RUN_ID in(Select max(RUN.RN_RUN_ID) From (((((((RELEASES JOIN RELEASE_CYCLES 
... 
TEST.TS_TYPE = 'LR-SCENARIO')AND TEST.TS_TEST_ID =145965 
ORDER BY TESTCYCL.TC_TESTCYCL_ID) 
ORDER BY TESTCYCL.TC_TESTCYCL_ID,STEP.ST_STEP_ORDER 

最終排序顯然是允許的,但在子查詢事實並非如此。因此,它應該結束:

... 
TEST.TS_TYPE = 'LR-SCENARIO')AND TEST.TS_TEST_ID =145965) 
ORDER BY TESTCYCL.TC_TESTCYCL_ID,STEP.ST_STEP_ORDER 

我無法測試,當我沒有你的模式,但一個簡單的演示可以幫助演示:

select d1.dummy 
from dual d1 
where d1.dummy in (
    select dummy 
    from dual d2 
    order by d2.dummy 
) 
order by d1.dummy; 

Error at Command Line : 6 Column : 3 
Error report - 
SQL Error: ORA-00907: missing right parenthesis 
00907. 00000 - "missing right parenthesis" 

通過移除內`順序:

select d1.dummy 
from dual d1 
where d1.dummy in (
    select dummy 
    from dual d2 
) 
order by d1.dummy; 

DUMMY 
----- 
X  

它期待看到)的而不是order by,所以錯誤確實讓一些感覺,一旦你知道什麼是錯誤的;但它並不能真正幫助你縮小範圍。

+0

謝謝亞歷克斯,我刪除了內部的訂單,它工作正常 – user3324344

+0

雙重查詢解釋清楚! –