3 Replies Latest reply on Jul 18, 2010 6:13 PM by 780914

    number precision too large

    721236
      THE FOLLOWING SIMPLE CODE IS GIVING ERROR even though i have given the definition (2,3) which is larger than the length of value 3.14 ?

      declare
      pi constant number(2,3):=3.14;
      r number(5) ;
      a number(5);
      begin
      r:=2;
      a:=pi*power(r,2);
      dbms_output.put_line('area is '||a);
      insert into areas values(r,a);
      end;

      ERROR at line 1:
      ORA-06502: PL/SQL: numeric or value error: number precision too large
      ORA-06512: at line 2
        • 1. Re: number precision too large
          706888
          Hi,

          Declare Pi as:
           pi   CONSTANT NUMBER (3, 2) := 3.14;
          instead ...
          It means: a length of 3 having 2 decimals.
          • 2. Re: number precision too large
            SomeoneElse
            pi constant number(2,3):=3.14;
            Perhaps you meant NUMBER(3,2).
            SQL> declare
              2     pi constant number(3,2):=3.14;
              3  begin
              4     dbms_output.put_line(pi);
              5  end;
              6  /
            3.14
            
            PL/SQL procedure successfully completed.
            
            SQL> declare
              2     pi constant number(3,2):=3.1415926;
              3  begin
              4     dbms_output.put_line(pi);
              5  end;
              6  /
            3.14
            • 3. Re: number precision too large
              780914
              When you declare a variable as number(x,y), it signifies the number contains "x" digits(0-9) out of which y are reserved for the decimal. This implies that x must be always greater than y. Cases when x<y and x=y will throw exception "number precision too large"