我是Oracle SQL的新手,对于我的生活,我无法弄清楚为什么我会继续收到错误"错过右括号"在我的代码上。我已经找到了缺失或额外的逗号和括号,但无法弄明白。请帮忙!我的查询如下:
CREATE VIEW PRODUCT_SUMMARY_V
AS SELECT
PROD_ID,
EXTRACT (CALENDAR_YEAR FROM TIME_ID) "YEAR",
EXTRACT (CALENDAR_MONTH_NAME FROM TIME_ID) "MONTH",
SUM(AMOUNT_SOLD) "TOTAL_AMOUNT_SOLD",
SUM(QUANTITY_SOLD) "TOTAL_QUANTITY_SOLD",
ROUND(SUM(AMOUNT_SOLD)/SUM(QUANTITY_SOLD),2) "AVG_SALE_PRICE"
FROM MY_SALES
GROUP BY PROD_ID, CALENDAR_YEAR, CALENDAR_MONTH_NAME
ORDER BY PROD_ID;
答案 0 :(得分:3)
您在TIME_ID
函数的帮助下从EXTRACT()
中提取了错误的值。
SQL> CREATE VIEW PRODUCT_SUMMARY_V
AS SELECT
PROD_ID,
EXTRACT (YEAR FROM TIME_ID) "YEAR",
EXTRACT (MONTH FROM TIME_ID) "MONTH",
SUM(AMOUNT_SOLD) "TOTAL_AMOUNT_SOLD",
SUM(QUANTITY_SOLD) "TOTAL_QUANTITY_SOLD",
ROUND(SUM(AMOUNT_SOLD)/ SUM(QUANTITY_SOLD),2) "AVG_SALE_PRICE"
FROM MY_SALES
GROUP BY PROD_ID, EXTRACT (YEAR FROM TIME_ID), EXTRACT (MONTH FROM TIME_ID)
ORDER BY PROD_ID;
View created.
但是,错误消息具有误导性,因为EXTRACT
函数的参数不正确,并将其视为表的列。语法检查器将语句视为SELECT EXTRACT(CALENDAR_YEAR FROM TIME_ID
。
SQL> SELECT EXTRACT(CALENDAR_YEAR FROM TIME_ID;
SELECT EXTRACT(CALENDAR_YEAR FROM TIME_ID
*
ERROR at line 1:
ORA-00907: missing right parenthesis
详细信息:Extract