学无止境
分类: Oracle
2013-12-11 15:50:11
跨字符集导入由于字段长度不足报错的问题
导入过程:ZHS16GBK->AL32UTF8
导入中文字符存放长度问题
增大导入表的精度
IMP-00019: row rejected due to ORACLE error 12899
IMP-00003: ORACLE error 12899 encountered
ORA-12899: value too large for column "LDY"."EXP_TAB"."NAME" (actual: 15, maximum: 10)
一种方法是修改字符集为ZHS16GBK后导入,然后再将字符集修改为AL32UTF8
但是查询时会报,ORA-29275: partial multibyte character错误
需要通过covert(char,'dest_char_set','source_char_set')进行转换。
select id,convert(name,'UTF8','ZHS16GBK') from ldy.exp_tab_3;
另一种比较便捷的方法是先导入表定义,再修改长度,再导入数据。
1.先将表定义导入
imp ldy/oracle file=exp_tab_ldy.dmp tables=exp_tab rows=n
2.将刚导入的表定义修改,拼写脚本如下:
SELECT 'ALTER TABLE ' || OWNER || '.' || TABLE_NAME || ' MODIFY (' ||
COLUMN_NAME || ' ' || DATA_TYPE || '(' || CEIL(DATA_LENGTH * 1.5) ||
'));'
FROM DBA_TAB_COLUMNS
WHERE OWNER = 'LDY'
AND DATA_TYPE IN ('CHAR', 'VARCHAR2', 'NCHAR', 'NVARCHAR2')
AND TABLE_NAME IN ('EXP_TAB');
3.再将数据导入
imp ldy/oracle file=exp_tab_ldy.dmp tables=exp_tab ignore=y
如果表比较多,例如近1个小时内只有imp导入创建的表,可以使用如下脚本:
SELECT 'ALTER TABLE ' || OWNER || '.' || TABLE_NAME || ' MODIFY (' ||
COLUMN_NAME || ' ' || DATA_TYPE || '(' || CEIL(DATA_LENGTH * 1.5) ||
'));'
FROM DBA_TAB_COLUMNS
WHERE OWNER = 'LDY'
AND DATA_TYPE IN ('CHAR', 'VARCHAR2', 'NCHAR', 'NVARCHAR2')
AND (OWNER, TABLE_NAME) IN
(select distinct owner, object_name
from dba_objects
where object_type like 'TABLE%'
and created > sysdate - 1/24);