当前位置: 代码迷 >> 综合 >> Oracle 11g 用数据泵 expdp/impdp 迁移数据时字符集不同的解决方法
  详细解决方案

Oracle 11g 用数据泵 expdp/impdp 迁移数据时字符集不同的解决方法

热度:5   发布时间:2023-12-18 09:30:59.0

提示:原则上,第一次创建数据库的时候就应该考虑好选择哪种字符集,一般字符集确定后不可修改,所以,修改字符集此方法慎用!不建议在已有大量表数据的库中使用!

一、查询两个库的字符集

select userenv('language') from dual;

源端:

SQL> select userenv('language') from dual;

USERENV('LANGUAGE')
----------------------------------------------------
AMERICAN_AMERICA.ZHS16GBK

目标端:

SQL> select userenv('language') from dual;

USERENV('LANGUAGE')
--------------------------------------------------------------------------------
AMERICAN_AMERICA.AL32UTF8

二、修改目标端字符集

SQL> alter system checkpoint;System altered.SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> 
SQL> 
SQL> startup mount;
ORACLE instance started.Total System Global Area 1586708480 bytes
Fixed Size		    2253624 bytes
Variable Size		 1040190664 bytes
Database Buffers	  536870912 bytes
Redo Buffers		    7393280 bytes
Database mounted.
SQL> 
SQL> 
SQL> alter system enable restricted session;System altered.SQL> alter system set job_queue_processes=0;System altered.SQL> alter system set aq_tm_processes=0;System altered.SQL> alter database open;Database altered.SQL> alter database character set internal_use ZHS16GBK;Database altered.SQL> alter system set nls_language='AMERICAN' scope=spfile;System altered.SQL> alter system set nls_territory='AMERICA' scope=spfile;System altered.SQL> shutdown immediate;            
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup;
ORACLE instance started.Total System Global Area 1586708480 bytes
Fixed Size		    2253624 bytes
Variable Size		 1040190664 bytes
Database Buffers	  536870912 bytes
Redo Buffers		    7393280 bytes
Database mounted.
Database opened.
SQL> select userenv('language') from dual;USERENV('LANGUAGE')
--------------------------------------------------------------------------------
AMERICAN_AMERICA.ZHS16GBK

三、迁移数据

导出:

[oracle@ora11g ~]$ expdp study/study tables=t_stu dumpfile=expdp_stu.dmp directory=data_dir

Export: Release 11.2.0.4.0 - Production on Tue Apr 9 10:04:47 2019

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "STUDY"."SYS_EXPORT_TABLE_01":  study/******** tables=t_stu dumpfile=expdp_stu.dmp directory=data_dir
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type TABLE_EXPORT/TABLE/TRIGGER
. . exported "STUDY"."T_STU"                             15.47 KB     398 rows
Master table "STUDY"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for STUDY.SYS_EXPORT_TABLE_01 is:
  /rmanbak/expdpdir/expdp_stu.dmp
Job "STUDY"."SYS_EXPORT_TABLE_01" successfully completed at Tue Apr 9 10:04:54 2019 elapsed 0 00:00:06

导入:

[oracle@oracle11g data_dir]$ impdp study/study directory=data_dir dumpfile=expdp_stu.dmp

Import: Release 11.2.0.4.0 - Production on Tue Apr 9 11:22:33 2019

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "STUDY"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "STUDY"."SYS_IMPORT_FULL_01":  study/******** directory=data_dir dumpfile=expdp_stu.dmp
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "STUDY"."T_STU"                             15.47 KB     398 rows
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type TABLE_EXPORT/TABLE/TRIGGER
Job "STUDY"."SYS_IMPORT_FULL_01" successfully completed at Tue Apr 9 11:22:38 2019 elapsed 0 00:00:03

 

  相关解决方案