Wednesday, January 7, 2009

Solution of ORA-01873: the leading precision of the interval is too small

Error Description
Running the following query produce error ORA-01873.
SQL> select count(*) from log_book where created < SYSDATE-interval '270' day;
select count(*) from log_book where created < SYSDATE-interval '270' day
*
ERROR at line 1:
ORA-01873: the leading precision of the interval is too small

Cause of The Problem
When Passing Datetime Interval with Precision > 2 will raise this error. In above we gave 270 which is 3 bytes and hence error occurs. This is as a result of the default scale (2) being smaller than the maximum (9).

Solution of The Problem

If you give precision greater than 2 then you explicitly give the value of the precision. Here 270 is 3 bytes. So we will give 3 after day like,
SQL>select count(*) from log_book where created <>

As default scale is 2 so,
SELECT count(*) from log_book where created <> will not raise error.

In order to use more than 2 we explicitly need to specify scale. For 4 bytes,
SELECT count(*) from log_book where created <>

No comments:

Post a Comment