DECLARE
CURSOR cur_r IS
(line 3) SELECT
Territories.TerritoryID,
Territories.TerritoryDescription,
count(orders.orderID) as sales,
to_char(orders.orderDate,'MON')
FROM
Territories
INNER JOIN Orders
on Territories.TerritoryID=orders.TerritoryID
GROUP BY
to_char(orders.orderDate,'MON')
ORDER BY
sales;
RES cur_r%ROWTYPE;
BEGIN
(line 20)OPEN cur_r;
LOOP
FETCH cur_r INTO RES;
exit WHEN cur_r%NOTFOUND;
dbms_output.Put_line(
'Employee ID : '
|| RES.TerritoryID
|| ' Date of Hire : '
|| RES.TerritoryDescription
);
END LOOP;
CLOSE cur_r;
END;
/
為什么我會收到如下錯誤
ORA-00979:不是 GROUP BY 運算式 ORA-06512:在第 3 行 ORA-06512:在第 20 行 ORA-06512:在“SYS.DBMS_SQL”,第 1721 行
uj5u.com熱心網友回復:
DECLARE
CURSOR cur_r IS
(line 3) SELECT
Territories.TerritoryID,
Territories.TerritoryDescription,
count(orders.orderID) as sales,
to_char(orders.orderDate,'MON')
FROM
Territories
INNER JOIN Orders
on Territories.TerritoryID=orders.TerritoryID
GROUP BY
to_char(orders.orderDate,'MON'),
Territories.TerritoryID,
Territories.TerritoryDescription,
orders.orderID
ORDER BY
sales;
RES cur_r%ROWTYPE;
BEGIN
(line 20)OPEN cur_r;
LOOP
FETCH cur_r INTO RES;
exit WHEN cur_r%NOTFOUND;
dbms_output.Put_line(
'Employee ID : '
|| RES.TerritoryID
|| ' Date of Hire : '
|| RES.TerritoryDescription
);
END LOOP;
CLOSE cur_r;
END;
/
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/338960.html
