Oracle 查询出现 ORA-00907: 缺少右括号
我已经阅读了其他缺少右括号的问题,但没有找到我的问题的答案。我认为这是一个语法错误,在结束之前切断了一切(我不是一个真正的 Oracle 人),但我不知道它在哪里。该查询应该提取客户 ID 以及该客户的最近一年的记录。参数是客户 ID 号(按地区唯一,但与组织不同)、地区和搜索年份。如果该地区没有检索年份的记录,则不应返回任何记录。
SELECT DISTINCT CUSTOMER.CUSTOMER_ID_ALT, tblMaxYear.maxYear
FROM CUSTOMER CROSS JOIN
(SELECT to_char(Max(tblYr.FISCAL_YEAR), 'YYYY') AS maxYear
FROM CUSTOMER AS tblYr
WHERE tblYr.DISTRICT_KEY= :district
AND tblYr.CUSTOMER_ID= :cust) tblMaxYear
WHERE CUSTOMER.DISTRICT_KEY=:district
AND CUSTOMER.CUSTOMER_ID= :cust
AND to_char(CUSTOMER.FISCAL_YEAR, 'YYYY') = :prmYear
I've read through the other missing right parenthesis questions and haven't found an answer to my problem. I assume it is a syntax error cutting things off before the end (I'm not really an Oracle guy) but I don't know where it is. The query is supposed to pull the customer ID and the latest year there is a record for that customer. The parameters are a customer ID number (unique by district but different from the organizational one), the district, and the year being searched. If there is no record for the searched year for that district, no records should be returned.
SELECT DISTINCT CUSTOMER.CUSTOMER_ID_ALT, tblMaxYear.maxYear
FROM CUSTOMER CROSS JOIN
(SELECT to_char(Max(tblYr.FISCAL_YEAR), 'YYYY') AS maxYear
FROM CUSTOMER AS tblYr
WHERE tblYr.DISTRICT_KEY= :district
AND tblYr.CUSTOMER_ID= :cust) tblMaxYear
WHERE CUSTOMER.DISTRICT_KEY=:district
AND CUSTOMER.CUSTOMER_ID= :cust
AND to_char(CUSTOMER.FISCAL_YEAR, 'YYYY') = :prmYear
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
删除AS中的AS:
AS可用于列别名,不可用于表别名
Remove the AS in:
AS can be used for column aliasing, not table aliasing