Si está tratando de usar un literal de intervalo en Oracle, pero sigue obteniendo el error "la precisión inicial del intervalo es demasiado pequeña", con suerte esto ayudará.
El Error
Aquí hay un ejemplo del error:
SELECT INTERVAL '125' YEAR
FROM DUAL;
Resultado:
ORA-01873: the leading precision of the interval is too small 01873. 00000 - "the leading precision of the interval is too small" *Cause: The leading precision of the interval is too small to store the specified interval. *Action: Increase the leading precision of the interval or specify an interval with a smaller leading precision. Error at Line: 9 Column: 17
La solución
Aquí se explica cómo solucionar el problema:
SELECT INTERVAL '125' YEAR(3)
FROM DUAL;
Resultado:
+125-00
Todo lo que hice fue agregar (3)
al YEAR
palabra clave. Esto especifica una precisión de 3.
La precisión predeterminada es 2, por lo que si no especificamos una precisión mayor, se produce el error.
Puede proporcionar una precisión de hasta 9.
Ejemplo:
SELECT INTERVAL '123456789' YEAR(9)
FROM DUAL;
Resultado:
+123456789-00
Y esto es lo que sucede si reducimos la precisión mientras mantenemos el mismo número:
SELECT INTERVAL '123456789' YEAR(5)
FROM DUAL;
Resultado:
Error starting at line : 1 in command - SELECT INTERVAL '123456789' YEAR(5) FROM DUAL Error at Command Line : 1 Column : 17 Error report - SQL Error: ORA-01873: the leading precision of the interval is too small 01873. 00000 - "the leading precision of the interval is too small" *Cause: The leading precision of the interval is too small to store the specified interval. *Action: Increase the leading precision of the interval or specify an interval with a smaller leading precision.
Mismo error que antes.
Además, cualquier valor superior a 9 genera un error:
SELECT INTERVAL '123456789' YEAR(20)
FROM DUAL;
Resultado:
Error starting at line : 1 in command - SELECT INTERVAL '123456789' YEAR(20) FROM DUAL Error at Command Line : 1 Column : 34 Error report - SQL Error: ORA-30088: datetime/interval precision is out of range 30088. 00000 - "datetime/interval precision is out of range" *Cause: The specified datetime/interval precision was not between 0 and 9. *Action: Use a value between 0 and 9 for datetime/interval precision.