1

Here's the procedure:

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);

Here's the error:

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 is a NUMBER(2,0) FK on a Sales table. Passing the number 2 to the procedure shouldn't be out of range of the NUMBER(2,0) data type.

Why does this procedure think the IN parameter is too large?

3
  • 2
    Did you try running the query inside the function with the parameter on Developer or SQL*Plus? Looks to me like your saleValue variable is too short for the result. Commented Jul 23, 2013 at 2:16
  • The error is at line 5 --> SELECT * INTO movieName, salevalue FROM ... What is a type of saleValue Sales.SaleValue%type ? The procedure is trying to assign to this variable a result of SUM( xxx ), which is of type NUMERIC. Commented Jul 23, 2013 at 3:35
  • That was exactly the problem. The NUMBER field for SaleValue was too small to hold the SUM of the sale values. Thanks @tilly31 and kordirko, problem resolved. Commented Jul 23, 2013 at 3:36

1 Answer 1

3

Your query selects SUM(s.SaleValue) into a variable saleValue defined as Sales.SaleValue%type.

Normally using the %type syntax is good practice, but only when it matches the assigned value. If Sales.SaleValue is defined with scale and precision it is quite likely that a SUM() of that column will blow the bounds of that definition. As appears to be the case here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.