错误 - ORA-00907:缺少右括号

时间:2013-05-17 05:36:44

标签: sql database oracle10g ora-00907

我是SQL的新手,当我尝试运行查询时出现错误“ERROR - ORA-00907:缺少右括号”,请帮我解决这个问题,请在下面找到查询 提前谢谢!

(SELECT
        DISTINCT d.order_key ord,
        d.order_status stat,
        m.order_call_key,
        m.opr_no opr_no,
        m.opr_step_no opr_step_no 
    FROM
        owi_order d,
        order_call m 
    WHERE
        d.rev_status = 'Complete' 
        AND d.order_type_cd <> 'ADPPO' 
        AND UPPER(d.pgm_id) = UPPER ('777') 
        AND (UPPER(m.init_callbrd_action_cd) IN ('MGWP', 'QWIP', 'RFI', 'RIOT', 'RIPI', 'RIR', 'RJSS', 'RNCR', 'RQAI', 'RSIR', 'RTQA') 
        OR (UPPER(m.cmpl_callbrd_action_cd) IN ('MGWP', 'QWIP', 'RFI', 'RIOT', 'RIPI', 'RIR', 'RJSS', 'RNCR', 'RQAI', 'RSIR', 'RTQA') 
        OR EXISTS  ( SELECT
            'x' 
        from
            order_call_ack a 
        where
            a.order_call_key=m.order_call_key 
            AND UPPER(a.ackd_callbrd_action_cd) IN ('MGWP', 'QWIP', 'RFI', 'RIOT', 'RIPI', 'RIR', 'RJSS', 'RNCR', 'RQAI', 'RSIR', 'RTQA') 
            AND a.active_ind <> 'N')) 
        and m.order_key = d.order_key), related_query AS ((SELECT
            s.related_order_key ord,
            s.order_key parent,
            b.order_call_key call_parent,
            o.order_call_key call 
        FROM
            related_obj s,
            owi_rep_query b,
            owi_order t,
            order_call o 
        WHERE
            s.order_key=b.ord 
            AND s.related_order_key = o.order_key 
            AND b.stat  IN ('Enqueued','Scheduled','Pulled') 
            AND s.related_obj_stat_cd <> 'DL' 
            AND s.related_order_key = t.order_key 
            AND t.rev_status IN ('Complete')  
            AND b.order_call_key <> o.order_call_key 
        UNION
        SELECT
            ord,
            to_number(null) parent,
            to_number(null) call_parent,
            order_call_key call 
        from
            owi_rep_query)), related_call_query AS (SELECT
        distinct ord,
        parent,
        MAX(call_parent) call_parent,
        call,
        (SELECT
            CASE m.call_status_nm  
                WHEN 'Completed' THEN m.cmpl_callbrd_action_cd 
                ELSE (SELECT
                    DISTINCT ackd_callbrd_action_cd 
                FROM
                    order_call_ack ock,
                    order_call ocaa 
                WHERE
                    ock.order_call_key = r.call 
                    AND ocaa.order_call_key = r.call 
                    AND ocaa.call_status_nm <> 'Completed' 
                    AND ock.ack_ts = (SELECT
                        MAX(ack_ts) 
                    FROM
                        order_call_ack t 
                    WHERE
                        t.order_call_key = ocaa.order_call_key 
                        AND t.active_ind <> 'N')) 
                END 
            FROM
                Order_call m 
            WHERE
                m.order_call_key = r.call) call_action 
        FROM
            related_query r 
        GROUP BY
            ord,
            parent,
            call),
            temp_rslt AS (SELECT
                RPAD(d.order_id,
                32,
                ' ') orderRecordIdTemp,
                TRIM(RPAD(m.acc_cd,
                3,
                ' '))||'/'||TRIM(RPAD(m.acc_pos_cd,
                3,
                ' '))||'/'|| RPAD(DECODE(m.work_loc_cd,
                '..',
                '',
                '...',
                '',
                m.work_loc_cd),
                3,
                ' ') accPosWl,
                LPAD(m.line_no,
                5,
                0) lineNumber,
                RPAD(m.call_id,
                8,
                ' ') callIdVal,
                RPAD(m.order_hld_ind,
                4,
                ' ') orderHldInd,
                RPAD(m.prty_no,
                4,
                ' ') prtyNo,
                RPAD(TO_CHAR(m.call_init_ts,
                'MM/DD HH24:MI'),
                11,
                ' ') callInitTs,
                RPAD(call_action,
                4,
                ' ') callAction,
                RPAD(TO_CHAR(m.ecd,
                'MM/DD HH24:MI'),
                11,
                ' ') ecdVal,
                RPAD(F_SUBPIPES(SUBSTR(REPLACE(NVL(m.remark_txt,
                TO_CLOB(' ')),
                '',
                ' '),
                1,
                40)),
                11,
                ' ') remarkTxt,
                LPAD(TRIM(m.order_call_key),
                40,
                ' ') orderCallKey,
                NVL(call_parent,
                0) call_parent,
                LPAD(a.parent,
                40,
                ' ') rel_key,
                d.order_key order_key,
                RPAD(m.prty_no,
                38,
                ' ') prty_no,
                RPAD(m.call_id,
                10,
                ' ') call_id,
                TRIM(RPAD(m.acc_cd,
                4,
                ' '))||'/'||TRIM(RPAD(m.acc_pos_cd,
                5,
                ' '))||'/'|| RPAD(DECODE(m.work_loc_cd,
                '..',
                '',
                '...',
                '',
                m.work_loc_cd),
                3,
                ' ') acc_pos_wl,
                RPAD(TO_CHAR(m.call_init_ts,
                'MM/DD/YYYY HH24:MI'),
                20,
                ' ') call_init_ts,
                m.opr_no opr_no,
                m.opr_step_no opr_step_no 
            FROM
                owi_order d,
                order_call m,
                related_call_query a 
            WHERE
                m.order_key=d.order_key 
                AND a.ord = d.order_key 
                AND m.order_call_key = a.call 
                AND m.init_callbrd_action_cd <> 'WIP') SELECT
                RPAD(LPAD(' ',
                (level - 1) * 2) || orderRecordIdTemp,
                32,
                ' ') orderRecordId,
                accPosWl,
                lineNumber,
                callIdVal,
                orderHldInd,
                prtyNo,
                callInitTs,
                callAction,
                ecdVal,
                remarkTxt,
                orderCallKey 
            from
                temp_rslt CONNECT 
            BY
                PRIOR orderCallKey = call_parent 
                AND PRIOR Order_key = rel_key START WITH orderCallKey IN (SELECT
                    b.orderCallKey 
                FROM
                    temp_rslt b 
                WHERE
                    NOT EXISTS (SELECT
                        'X' 
                    FROM
                        temp_rslt v 
                    WHERE
                        v.order_key = b.rel_key) 
                    AND (SELECT
                        COUNT(g.orderCallKey) 
                    from
                        temp_rslt g 
                    WHERE
                        g.orderCallKey = b.orderCallKey) = 1)  
                ORDER SIBLINGS BY
                    prtyNo,
                    callInitTs,
                    orderRecordIdTemp,
                    callIdVal,
                    orderCallKey

编辑1:添加了代码标签!

1 个答案:

答案 0 :(得分:1)

@ user2392549:从Oracle站点下载并使用SQLDeveloper。它是一个免费软件,并提供了各种风格的良好格式选项。查询需要正确格式化,然后针对缺少的括号进行调试。此外,SQL Developer为您提供了在拼写错误或执行期间指出问题所在的行号的优势。

下载链接:http://www.oracle.com/technetwork/developer-tools/sql-developer/downloads/index.html