从 DB2 移植到 ORACLE - ORA-00907:缺少右括号
Posted
技术标签:
【中文标题】从 DB2 移植到 ORACLE - ORA-00907:缺少右括号【英文标题】:PORTING FROM DB2 TO ORACLE - ORA-00907: missing right parenthesis 【发布时间】:2013-07-12 09:44:32 【问题描述】:我在第 7 行,第 6 列收到错误“ORA-00907:缺少右括号” 当我在 ORACLE 11g DB 上启动此查询时:
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)
我怎样才能改变它以便在没有错误的情况下进行移植?
【问题讨论】:
“rownum”在“order by”之前应用,所以在你的内部查询中,“order by”没有任何作用 你是对的!我正在尝试将 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 仅获取前 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
)
【讨论】:
以上是关于从 DB2 移植到 ORACLE - ORA-00907:缺少右括号的主要内容,如果未能解决你的问题,请参考以下文章
Oracle 利用PLSQL一分钟将表结构(PROJ),从A库移植到B库,一分钟将A库中表数据移植到B库中!!!
Oracle 利用PLSQL一分钟将表结构(PROJ),从A库移植到B库,一分钟将A库中表数据移植到B库中!!!
我需要从Oracle Apex连接到DB2 AS / 400数据库。