Concatenating numbers in virtual column expression throws ORA-12899: value too large for column Concatenating numbers in virtual column expression throws ORA-12899: value too large for column oracle oracle

Concatenating numbers in virtual column expression throws ORA-12899: value too large for column


Your numbers are not constrained. With single digit (positive) numbers you know the concatendated length can only be three, but the virtual column has to be large enough for any number - so it looks like it's allowing up to 40 digits for the implicit format model (38 significant digits, the decimal separator, and the sign; @collspar's lexicalisation).

Having said that, constraining the number column wouldn't be reflected in the virtual column length - making both columns NUMBER(1,0) still leaves the concatenation requiring 81 characters. Taking the substring of the generated value won't work either, in this case getting ORA-12899: value too large for column "TEXT" (actual: 10, maximum: 40). Supplying a format model for each to_char() call, e.g. of FM999), would work but restricts the values either side of the underscore rather than the overall length directly.

If you want to restrict the column size, you can cast it to the same data type and size, which is more explicit:

text VARCHAR2(10) generated always as     (cast(to_char(id)||'_'||to_char(num) as VARCHAR2(10))) VIRTUAL