Oracle过程错误:数值或值错误:数字精度太大?

时间:2013-07-23 01:29:45

标签: oracle stored-procedures plsql

以下是程序:

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是Sales表上的NUMBER(2,0)FK。将数字2传递给过程不应超出NUMBER(2,0)数据类型的范围。

为什么这个程序认为IN参数太大?

1 个答案:

答案 0 :(得分:3)

您的查询会将SUM(s.SaleValue)选择为定义为saleValue的变量Sales.SaleValue%type

通常使用%type语法是一种很好的做法,但只有当它与指定的值匹配时才是这样。如果使用缩放和精度定义Sales.SaleValue,那么该列的SUM()很可能会破坏该定义的边界。就像这里的情况一样。