在工作中遇见 ORA-00936: missing expression 报错,sql 如下
SELECT
auditEntry.FContractBillID,
auditEntry.FProgrammingContractID,
SUM (auditEntry.FAmount) FAmount,
SUM (auditEntry.FVat) FVat,
audit.FNegChgCtrlModel FNegChgCtrlModel,
SUM (
CASE
WHEN auditEntry.FAmount < 0 THEN
auditEntry.FAmount
ELSE
0
END
) FNegAuditAmt,
SUM (
CASE
WHEN auditEntry.FAmount < 0 THEN
0
ELSE
auditEntry.FAmount
END
) FPosAuditAmt
FROM
T_CON_ChangeAuditBill audit
JOIN T_CON_ChangeAuditBillProgEntry auditEntry ON auditEntry.FParentID = audit.FID
WHERE
audit.FID = 'qiMgC487SKemItcJN/cm+XARYRc='
GROUP BY
auditEntry.FContractBillID,
auditEntry.FProgrammingContractID,
audit.FNegChgCtrlModel
初步定位以为是SUM 函数或者group by问题,但是去掉sum和group by 仍然报错ORA-00936: missing expression。
后取消关联表查询,使用单表T_CON_ChangeAuditBill ,仍然报同样的错。
实在郁闷,修改T_CON_ChangeAuditBill的别名audit为auditBill 如下sql
SELECT
auditEntry.FContractBillID,
auditEntry.FProgrammingContractID,
SUM (auditEntry.FAmount) FAmount,
SUM (auditEntry.FVat) FVat,
auditBill.FNegChgCtrlModel FNegChgCtrlModel,
SUM (
CASE
WHEN auditEntry.FAmount < 0 THEN
auditEntry.FAmount
ELSE
0
END
) FNegAuditAmt,
SUM (
CASE
WHEN auditEntry.FAmount < 0 THEN
0
ELSE
auditEntry.FAmount
END
) FPosAuditAmt
FROM
T_CON_ChangeAuditBill auditBill
JOIN T_CON_ChangeAuditBillProgEntry auditEntry ON auditEntry.FParentID = auditBill.FID
WHERE
auditBill.FID = 'qiMgC487SKemItcJN/cm+XARYRc='
GROUP BY
auditEntry.FContractBillID,
auditEntry.FProgrammingContractID,
auditBill.FNegChgCtrlModel
执行成功!!!百度后得知audit为oracle中的审计功能关键字,不能作为表的别名使用
注:由于开发库使用的是sql sever,测试库是oracle,因此只有测试库出现该问题
。