Oracle 查询出现 ORA-00907: 缺少右括号

发布于 2024-12-25 15:28:43 字数 595 浏览 2 评论 0原文

我已经阅读了其他缺少右括号的问题,但没有找到我的问题的答案。我认为这是一个语法错误,在结束之前切断了一切(我不是一个真正的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人│生佛魔见 2025-01-01 15:28:43

删除AS中的AS:

FROM CUSTOMER AS tblYr

AS可用于列别名,不可用于表别名

Remove the AS in:

FROM CUSTOMER AS tblYr

AS can be used for column aliasing, not table aliasing

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文