ORA-00933:SQL 命令未正确结束(查看脚本)

问题描述 投票:0回答:1

我收到这个错误

ORA-00933: SQL 命令未正确结束

来自以下视图脚本。 :

CREATE OR REPLACE VIEW MY_SCRIPT AS (
SELECT * FROM
(
    SELECT 
        EFFECTIVE_DT,
        SOURCE_CD,
        VIEW_CD,
        SDEX_TRAN_CODE TRANSACTION_CD,
        'missing' TRANSACTION_DESC,
        'missing' TRANSACTION_CATEGORY_TXT,
        'Y' TRANSACTION_CODE_ACTIVE_IND,
        Trunc(SYSDATE) TRANSACTION_CODE_START_DT,
        NULL TRANSACTION_REVERSAL_CD,
        NULL PRINCIPLE_MULTIPLICATION_NBR,
        NULL INCOME_MULTIPLICATION_NBR,
        NULL SHARES_MULTIPLICATION_NBR,
        NULL COST_MULTIPLICATION_NBR,
        'INVEST1' ACCOUNTING_SYSTEM_CD,
        NULL TRXDSCCD, 
        NULL USERDEFTRXDSC 
    FROM TRD_FPCMS_TRANS_FULL_01_STG
    WHERE SDEX_TRAN_CODE IS NOT NULL
    AND SOURCE_CD != 'INSTIO'
    UNION
    SELECT 
        EFFECTIVE_DT,
        SOURCE_CD,
        VIEW_CD,
        SDEX_TRAN_CODE TRANSACTION_CD,
        'missing' TRANSACTION_DESC,
        'missing' TRANSACTION_CATEGORY_TXT,
        'Y' TRANSACTION_CODE_ACTIVE_IND,
        Trunc(SYSDATE) TRANSACTION_CODE_START_DT,
        NULL TRANSACTION_REVERSAL_CD,
        NULL PRINCIPLE_MULTIPLICATION_NBR,
        NULL INCOME_MULTIPLICATION_NBR,
        NULL SHARES_MULTIPLICATION_NBR,
        NULL COST_MULTIPLICATION_NBR,
        'INVEST1' ACCOUNTING_SYSTEM_CD,
        NULL TRXDSCCD,
        NULL USERDEFTRXDSC
    FROM TRD_FPCMS_TRANS_FULL_01_STG
    WHERE SDEX_TRAN_CODE IS NOT NULL
) stg
WHERE NOT EXISTS (
    SELECT 1
    FROM accounting_transaction_code tgt
    WHERE tgt.TRANSACTION_CD = stg.TRANSACTION_CD
)) -- removed paranthesis here... 
UNION
SELECT 
    businessdt effective_dt,
    holding_source_cd source_cd,
    holding_view_cd view_cd,
    txn.transaction_cd, 
    txn.tran_desc transaction_desc,
    'missing' transaction_category_txt,
    'Y' transaction_code_active_ind,
    TRUNC(sysdate) transaction_code_start_dt,
    NULL transaction_reversal_cd,
    NULL principle_multiplication_nbr,
    NULL income_multiplication_nbr,
    NULL shares_multiplication_nbr,
    NULL cost_multiplication_nbr,
    'GENEVA' ACCOUNTING_SYSTEM_CD,
    tk.TRXDSCCD,
    tk.USERDEFTRXDSC
FROM transactions_gva_kfk_stg tks
JOIN cde_stg.TRANSACTIONS_IA_KFK_STG tk
ON tks.KAFKA_LOAD_ID = tk.KAFKA_LOAD_ID
JOIN (
    SELECT DISTINCT
        CASE WHEN LEAD(transaction_cd) OVER (ORDER BY transaction_cd) = transaction_cd
            THEN  substr(transaction_cd,1,6)||substr(sys_guid(),6,6)
            ELSE transaction_cd  END transaction_cd,
            tran_desc
    FROM (
        SELECT 
            CASE WHEN (
                SELECT COUNT(1) 
                FROM accounting_transaction_code 
                WHERE transaction_cd =  UPPER(substr(trxcd,1,12))
            ) = 0
            THEN  UPPER(substr(trxcd,1,12))
            WHEN (
                SELECT COUNT(1) 
                FROM accounting_transaction_code 
                WHERE transaction_cd =  UPPER(substr(trxcd,1,6)||substr(trxcd,-6))
            ) = 0
            THEN  UPPER(substr(trxcd,1,6)||substr(trxcd,-6))
             ELSE substr(trxcd,1,6)||substr(sys_guid(),6,6)
            END transaction_cd,  tran_desc
        FROM (
            SELECT DISTINCT 
                gva.trxcd tran_desc, 
                regexp_replace(UPPER(trxcd),'[^A-Z0-9]') trxcd
            FROM transactions_gva_kfk_stg gva
            WHERE NOT EXISTS
            (SELECT 1
            FROM accounting_transaction_code tgt
            WHERE tgt.transaction_desc = gva.trxcd)
            ) gva
        ORDER BY transaction_cd
        )) txn -- added paranthetis here
ON txn.tran_desc = tks.trxcd
WHERE NOT EXISTS (
    SELECT 1
    FROM accounting_transaction_code tgt
    WHERE tgt.transaction_desc = tks.trxcd
));

我已经尝试调试了好几个小时,但一直没能找到为什么会出现此错误。是否有能够快速查找语法错误的网站或程序?不知道在这里做什么,但会很感激任何帮助。

sql plsql plsqldeveloper
1个回答
0
投票

你还没有解释你的查询应该做什么,而且它很大,所以我不确定这在逻辑上是否是你想要实现的。但这应该可以解决您的语法错误。我删除了一个括号并添加了另一个(检查评论)。

CREATE OR REPLACE VIEW MY_SCRIPT AS (
SELECT * FROM
(
    SELECT 
        EFFECTIVE_DT,
        SOURCE_CD,
        VIEW_CD,
        SDEX_TRAN_CODE TRANSACTION_CD,
        'missing' TRANSACTION_DESC,
        'missing' TRANSACTION_CATEGORY_TXT,
        'Y' TRANSACTION_CODE_ACTIVE_IND,
        Trunc(SYSDATE) TRANSACTION_CODE_START_DT,
        NULL TRANSACTION_REVERSAL_CD,
        NULL PRINCIPLE_MULTIPLICATION_NBR,
        NULL INCOME_MULTIPLICATION_NBR,
        NULL SHARES_MULTIPLICATION_NBR,
        NULL COST_MULTIPLICATION_NBR,
        'INVEST1' ACCOUNTING_SYSTEM_CD,
        NULL TRXDSCCD, 
        NULL USERDEFTRXDSC 
    FROM TRD_FPCMS_TRANS_FULL_01_STG
    WHERE SDEX_TRAN_CODE IS NOT NULL
    AND SOURCE_CD != 'INSTIO'
    UNION
    SELECT 
        EFFECTIVE_DT,
        SOURCE_CD,
        VIEW_CD,
        SDEX_TRAN_CODE TRANSACTION_CD,
        'missing' TRANSACTION_DESC,
        'missing' TRANSACTION_CATEGORY_TXT,
        'Y' TRANSACTION_CODE_ACTIVE_IND,
        Trunc(SYSDATE) TRANSACTION_CODE_START_DT,
        NULL TRANSACTION_REVERSAL_CD,
        NULL PRINCIPLE_MULTIPLICATION_NBR,
        NULL INCOME_MULTIPLICATION_NBR,
        NULL SHARES_MULTIPLICATION_NBR,
        NULL COST_MULTIPLICATION_NBR,
        'INVEST1' ACCOUNTING_SYSTEM_CD,
        NULL TRXDSCCD,
        NULL USERDEFTRXDSC
    FROM TRD_FPCMS_TRANS_FULL_01_STG
    WHERE SDEX_TRAN_CODE IS NOT NULL
) stg
WHERE NOT EXISTS (
    SELECT 1
    FROM accounting_transaction_code tgt
    WHERE tgt.TRANSACTION_CD = stg.TRANSACTION_CD
)) -- removed paranthesis here...  -- try executing this query up
UNION
SELECT 
    businessdt effective_dt,
    holding_source_cd source_cd,
    holding_view_cd view_cd,
    txn.transaction_cd, 
    txn.tran_desc transaction_desc,
    'missing' transaction_category_txt,
    'Y' transaction_code_active_ind,
    TRUNC(sysdate) transaction_code_start_dt,
    NULL transaction_reversal_cd,
    NULL principle_multiplication_nbr,
    NULL income_multiplication_nbr,
    NULL shares_multiplication_nbr,
    NULL cost_multiplication_nbr,
    'GENEVA' ACCOUNTING_SYSTEM_CD,
    tk.TRXDSCCD,
    tk.USERDEFTRXDSC
FROM transactions_gva_kfk_stg tks
JOIN cde_stg.TRANSACTIONS_IA_KFK_STG tk
ON tks.KAFKA_LOAD_ID = tk.KAFKA_LOAD_ID
JOIN (
    SELECT DISTINCT
        CASE WHEN LEAD(transaction_cd) OVER (ORDER BY transaction_cd) = transaction_cd
            THEN  substr(transaction_cd,1,6)||substr(sys_guid(),6,6)
            ELSE transaction_cd  END transaction_cd,
            tran_desc
    FROM (
        SELECT 
            CASE WHEN (
                SELECT COUNT(1) 
                FROM accounting_transaction_code 
                WHERE transaction_cd =  UPPER(substr(trxcd,1,12))
            ) = 0
            THEN  UPPER(substr(trxcd,1,12))
            WHEN (
                SELECT COUNT(1) 
                FROM accounting_transaction_code 
                WHERE transaction_cd =  UPPER(substr(trxcd,1,6)||substr(trxcd,-6))
            ) = 0
            THEN  UPPER(substr(trxcd,1,6)||substr(trxcd,-6))
             ELSE substr(trxcd,1,6)||substr(sys_guid(),6,6)
            END transaction_cd,  tran_desc
        FROM (
            SELECT DISTINCT 
                gva.trxcd tran_desc, 
                regexp_replace(UPPER(trxcd),'[^A-Z0-9]') trxcd
            FROM transactions_gva_kfk_stg gva
            WHERE NOT EXISTS
            (SELECT 1
            FROM accounting_transaction_code tgt
            WHERE tgt.transaction_desc = gva.trxcd)
            ) gva
        ORDER BY transaction_cd
        )) txn -- added paranthetis here
ON txn.tran_desc = tks.trxcd
WHERE NOT EXISTS (
    SELECT 1
    FROM accounting_transaction_code tgt
    WHERE tgt.transaction_desc = tks.trxcd
));
© www.soinside.com 2019 - 2024. All rights reserved.