oracle修改字符集_关于现有数据库字符集转换

论坛 期权论坛 脚本     
已经匿名di用户   2022-5-29 19:26   2679   0
上边蓝字关注我们

3106290d9660f42184a7eaa7ecefd8bd.png

本文演示oracle官方的字符集迁移工具DMU

  1. alter database character set internal_use

这个命令到底能不能用呢,在oracle database 19c版本中,无论是non_cdb,还是pdb,通过实践来看,还是能用的。

但是!但是!但是!

有谁敢用呢?4ec2baaee6e7ff77f2b26c37e097a97d.png

  • non_cdb

SYS@orcl> startup restrictORACLE instance started.SYS@orcl> alter database character set internal_use zhs16gbk;                            Database altered.SYS@orcl> shutdown immediateDatabase closed.Database dismounted.ORACLE instance shut down.SYS@orcl> startupORACLE instance started.SYS@orcl> select userenv('language') from dual;USERENV('LANGUAGE')----------------------------------------------------AMERICAN_AMERICA.ZHS16GBK
  • pdb

SQL> show pdbs;    CON_ID CON_NAME                       OPEN MODE  RESTRICTED---------- ------------------------------ ---------- ----------         2 PDB$SEED                       READ ONLY  NO         3 PDB1                           MOUNTEDSQL> alter pluggable database pdb1 open;Pluggable database altered.SQL> select userenv('language') from dual;USERENV('LANGUAGE')----------------------------------------------------AMERICAN_AMERICA.AL32UTF8SQL> alter pluggable database close immediate;Pluggable database altered.SQL> alter pluggable database open read write restricted;Pluggable database altered.SQL> alter session set container=pdb1;Session altered.SQL> alter database character set internal_use zhs16gbk;Database altered.SQL> alter pluggable database pdb1 close;Pluggable database altered.SQL> alter pluggable database pdb1 open;Pluggable database altered.SQL> alter session set container=pdb1;Session altered.SQL> select userenv('language') from dual;USERENV('LANGUAGE')----------------------------------------------------AMERICAN_AMERICA.ZHS16GBKSQL> 

2.我们来看看19c版本中官方手册sql language reference中alter database characterset的描述

CHARACTER SET, NATIONAL CHARACTER SETYou can no longer change the database character set or the national character set using the ALTER DATABASE statement. Refer to Oracle Database Globalization Support Guide for information on database character set migration. 

那么也就是说,这个语法官方已经不支持了。

另外一篇字符集迁移的官方手册是这么说的

Changing the Database Character Set of an Existing DatabaseDatabase character set migration is an intricate process that typically involves three stages: data scanning, data cleansing, and data conversion.Before you change the database character set, you must identify possible database character set conversion problems and truncation of data. This step is called data scanning. Data scanning identifies the amount of effort required to migrate data into the new character encoding scheme before changing the database character set. Some examples of what may be found during a data scan are the number of schema objects where the column widths need to be expanded and the extent of the data that does not exist in the target character repertoire. This information helps to determine the best approach for converting the database character set.After the potential data issues are identified, they need to be cleansed properly to ensure the data integrity can be preserved during the data conversion. The data cleansing step could require significant time and effort depending on the scale and complexity of the data issues found. It may take multiple iterations of data scanning and cleansing in order to correctly address all of the data exceptions.The data conversion is the process by which the character data is converted from the source character set into the target character set representation. Incorrect data conversion can lead to data corruption, so perform a full backup of the database before attempting to migrate the data to a new character set.There are two approaches for migrating the database character set:    Migrating Character Data Using the Database Migration Assistant for Unicode    Migrating Character Data Using a Full Export and Import

也就是说对已存在的数据库进行字符集的修改,官方只支持dmu和数据泵的方式。

3.我们来体验一下dmu,dmu只能把字符集转换为al32utf8和utf8。

dmu工具在$ORACLE_HOME/dmu目录下,sh dmu.sh,需要图形化界面

0dd37d2a701ad3e9c1a3d1c1ed76b235.png

连接到要做字符集迁移的数据库,连接方式类似pl/sql developer,但是连接时有报错,原来是要跑一个脚本。

9b9825061e3b863935a9f1597746c388.png

按提示执行脚本

SYS@orcl> @?/rdbms/admin/prvtdumi.plbLibrary created.Package created.No errors.Package body created.No errors.

连接建好以后进入操作界面,首先要安装资料库

6f9a06fc3d3a075f777b1cd234e74048.png

选择目标字符集

4613a280164e7517bb7a0a0fb0edb62a.png

创建字符集资料库

08b814b56a6ea2f5d626fee411f6804f.png

进入转换助手流程界面,第一步的资料库已经完成。

3ac35a4617f5ec02d472f29d1170bf44.png

开始第二步,扫描数据库

b48eae82f497450d536b8553b99b0b93.png

3961cc0836a78c61d2a82e506d7d7029.png

cf5a73593c5a78d2593b2736afff74b6.png

ebb6843822e85e029d99f5538c3455ab.png

fef2e7f9251e21440cccad85a7a3427a.png

完成后,第三部如果没有问题的话,也算是通过了

5537e3b89fee40753234176ca098d9de.png

现在开始最后一步的转换步骤

84cb76c061c20703dc626ffa2a3dfb0d.png

361a3d98c786c4082ab6df37d142c13b.png

c85fdcebaf4334053f12a7bee9d42558.png

4.最后确认一下字符集是否转换成功。
[oracle@vm1 dmu]$ sqlplus / as sysdbaSYS@orcl> select userenv('language') from dual;USERENV('LANGUAGE')----------------------------------------------------AMERICAN_AMERICA.AL32UTF8

bd85bb7341e2d63c643e34fc94692d61.png

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:81
帖子:4969
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP