很多时间,再插入值的时候,会出现超出指定的限制的最大的数。如果允许精度确实可以使用substr或者rpad来限制返回的长度。如果不允许精度确实,则需要
增加字段的精度。
SQL> desc er_test;
Name Null? Type
----------------------------------------- -------- ----------------------------
NAME VARCHAR2(10)
SQL> insert into er_test values ('111111111111111111111111');
insert into er_test values ('111111111111111111111111')
*
ERROR at line 1:
ORA-12899: value too large for column "TEST"."ER_TEST"."NAME" (actual: 24, maximum: 10)
利用substr截取字符串长度
SQL> select length(substr('111111111111111111111111',1,10)) from dual;
LENGTH(SUBSTR('111111111111111111111111',1,10))
-----------------------------------------------
10
利用rpad截取字符串长度
SQL> select length(rpad('111111111111111111111111',10)) from dual;
LENGTH(RPAD('111111111111111111111111',10))
-------------------------------------------
10
SQL> insert into er_test values(substr('111111111111111111111111',1,10));
1 row created.
SQL> insert into er_test values(rpad('111111111111111111111111',10));
1 row created.
如果不允许有字符串的精度确实,则可以加大字段属性长度
SQL> alter table er_test modify name varchar2(50);
Table altered.
注意:只能增加长度,不能减少,否则会报错
SQL> alter table er_test modify name varchar2(5);
alter table er_test modify name varchar2(5)
*
ERROR at line 1:
ORA-01441: cannot decrease column length because some value is too big