0

当我在 ORACLE 11g DB 上启动此查询时,我在第 7 行第 6 行收到错误“ORA-00907:缺少右括号”:

 SELECT B.ID_COND AS IDCOND,B.ID_PAYMENT AS IDPAYMENT, B.DT_SCAD AS DATASCAD, B.DT_PAYMENT AS DATAPAYMENT,B.DE_CHANNELPAG AS CHANNELPAYMENT, B.DT_STARTVALID AS DATASTART, B.DT_ENDVALID AS DATAEND,
            B.IM_TOTAL AS TOTAL, B.ST_PAYMENT AS STATECOND, B.CO_CIP AS codCIP, B.ID_PEND AS IDPEND, B.TI_PAYMENT AS TIPOPAYMENT,
            B.cause_PAYMENT AS causaleCOND, B.IM_PAYMENT AS amountPAYMENT, B.DE_MIDDLEPAYMENT AS MIDDLEPAYMENT, B.DE_NOTEPAYMENT as notePAYMENT,    
            (select st_PAYMENT from QLT.paymnts P
                where P.ID_COND=B.ID_COND
      AND ROWNUM <= 1
                order by (CASE WHEN P.st_PAYMENT='ES' THEN 1 ELSE 0 END) DESC, TS_INSMNT DESC
            ) AS STATEPAYMENT
    FROM  QLT.JLTCOPD B
        WHERE  B.ID_PEND = '269' AND B.TI_PAYMENT = 'S' 
        ORDER BY B.DT_SCAD ASC, DT_STARTVALID ASC

尝试删除此行:'order by (CASE WHEN P.st_PAYMENT='ES' THEN 1 ELSE 0 END) DESC, TS_INSMNT DESC' 不显示错误并返回结果。

我正在尝试将 DB2 查询转换为 ORACLE,原来的 DB2 内部查询是:

(select st_PAYMENT from QLT.paymnts P where P.ID_COND=B.ID_COND order by (CASE WHEN P.st_PAYMENT='ES' THEN 1 ELSE 0 END) DESC, TS_INSMNT DESC fetch first 1 rows only) 

如何更改它以便进行无错误的移植?

4

1 回答 1

1

尝试将内部查询替换为:

(
    select st_PAYMENT FROM 
    (
        select st_PAYMENT from QLT.paymnts P
        where P.ID_COND=B.ID_COND
        order by (CASE WHEN P.st_PAYMENT='ES' THEN 1 ELSE 0 END) DESC, TS_INSMNT DESC
    )
    WHERE ROWNUM <= 1
)
于 2013-07-12T10:01:15.960 回答