1
這裏的程序:Oracle過程錯誤:數字或值錯誤:數字精度太大?
CREATE OR REPLACE PROCEDURE GetBestSellingMovieByTimeId(timeId IN NUMBER) IS
movieName Movie.Name%type;
saleValue Sales.SaleValue%type;
BEGIN
SELECT * INTO movieName, salevalue FROM (
SELECT m.Name, SUM(s.SaleValue) AS TotalSales
FROM Sales s
INNER JOIN Movie m ON s.MovieId = m.MovieId
WHERE s.TimeId = timeId
GROUP BY m.Name ORDER BY TotalSales DESC
) WHERE ROWNUM = 1;
dbms_output.put_line(movieName ||', ' || saleValue);
END;
/
exec GetBestSellingMovieByTimeId(2);
這裏的錯誤:
Error starting at line 190 in command: exec GetBestSellingMovieByTimeId(2)
Error report:
ORA-06502: PL/SQL:numeric or value error: number precision too large
ORA-06512: at "CM420B17.GETBESTSELLINGMOVIEBYTIMEID", line 5
ORA-06512: at line 1
06502. 00000 - "PL/SQL: numeric or value error%s"
*Cause:
*Action:
TIMEID是一個數字(2,0)FK在銷售表。將數字2傳遞給過程不應超出NUMBER(2,0)數據類型的範圍。
爲什麼這個程序認爲IN參數太大?
您是否嘗試使用Developer或SQL * Plus上的參數在函數內部運行查詢?在我看來,你的saleValue變量對於結果來說太短了。 – tilley31
錯誤在第5行 - > SELECT * INTO movieName,salevalue FROM ...什麼是saleValue Sales.SaleValue%類型的類型?該過程試圖爲此變量分配SUM(xxx)的結果,該結果的類型爲NUMERIC。 – krokodilko
這正是問題所在。 SaleValue的NUMBER字段太小,無法保存銷售額的總和。謝謝@ tilly31和kordirko,問題已解決。 – Chaddeus