先上结论:
新数据库如果是 AL32UTF-8 ,因为字符集大,所以同样的内容,占用的字节多。结果就是容易触发一个错误:
ORA-12899: value too large for column CONADDR (actual: 64, maximum: 60)
为了避免导入时发生这个错误,解决思路就是:
dmp文件使用的字符集和导入目标服务器字符集一致。
为了达到这一目标,最简单的方式:
-- 保证导入目标服务器的字符集,客户端和服务器一致
SQL> select userenv('language') from dual; --服务器字符集
SQL> !env|grep NLS; --客户端字符集
-- 用目标服务器的客户端,执行导出命令,导出dmp文件, 导出时完成字符集转换工作
另一种比较便捷的方法是先导入表定义,再修改长度,再导入数据。
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);
impdp XXUSER/xxPwd dumpfile=nc501.dmp directory=DATA_PUMP_DIR REMAP_SCHEMA=NNC_DATA:NC501 parallel=2 exclude=CONSTRAINT exclude=INDEX
nc501.dmp 必需放到 DATA_PUMP_DIR对应路径中。
select * from dba_directories where directory_name like '%PUMP%'
因为导入数据,需要大量权限:
grant connect,dba to XXUSER;
grant read, write on directory DATA_PUMP_DIR to XXUSER;
expd xxxusername/xxxpwd@orcl dumpfile=xxx.dmp schemas=anotherUsername
log=D:\bak\xxx.log buffer=4096000 recordlength=65535 direct=y statistics=none
导出环境:
windows: hkey_local_mechine\software\oracle\key_oraDb11g_home1
SIMPLIFIED CHINESE_CHINA.ZHS16GBK
NLS_LANG=SIMPLIFIED CHINESE_CHINA.ZHS16GBK
导入环境
Linux:
env|grep NLS
NLS_LANG=SIMPLIFIED CHINESE_CHINA.AL32UTF8
导入:
先修改导入环境,NLS_LANG:
export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK"
export NLS_LANG="SIMPLIFIED CHINESE_CHINA.AL32UTF8"
create tablespace xxx datafile '/u01/app/oracle/oradata/orcl/xxx.dbf' size 2048M;
create user xxx identified by pwdxxx default tablespace xxxspacename temporary tablespace temp;
网友评论