Error this answers
ORA-01438: value larger than specified precision allowed for this column
NUMBER(p) holds at most p digits, so the largest value is p nines. When an insert fails with ORA-01438, or a sequence is creeping toward a column's limit, this prints that maximum so you don't have to count nines.
Usage
SQL> @pmx.sql 10
9999999999
-- pmx.sql: the largest value a NUMBER(p) column accepts
-- Copyright (c) HASHJOIN. MIT License (https://hashjoin.com/kb/license/)
-- https://hashjoin.com/kb/oracle/number-precision-max-value/
--
-- Usage: @pmx.sql <precision>
-- @pmx.sql 10 9999999999
col max_value format 999999999999999999999999999999999999999999999999999999999
select to_number(rpad('1',&&1+1,'0'))-1 max_value from dual
/curl -O https://hashjoin.com/kb/oracle/number-precision-max-value/pmx.sql
Gotchas
- With a scale, fewer digits are left for the integer part.
NUMBER(p,s)holds at most pās digits before the decimal point, soNUMBER(10,2)tops out at 99,999,999.99. Run@pmx.sql 8for its integer part. - Plain
NUMBERhas no such limit (up to 38 significant digits), so ORA-01438 always points at a column declared with a precision. - To find which column it was, the error doesn't say: compare the values in the failing statement with
dba_tab_columns.data_precisionfor the target table.
Tired of fixing the same thing twice?
HASHJOIN turns the checks and fixes your on-call runs by hand into tooling that gives the same answer every time. Fixed scope, and you own all of the code.
New fixes and field notes by email, about once a month.