在windows 7 64位上安装Oracle 12c没有设定字符集,采用的是操作系统默认字符集:WE8MSWIN1252,将字符集修改为:ZHS16GBK。由于过程不可逆,首先需要备份数据库。
1.数据库全备
2.查询当前字符集
PARAMETER VALUE
------------------------------------------------------------ ------------------------------------------------------------
NLS_CHARACTERSET WE8MSWIN1252
SQL>
3.关闭数据库
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
4.启动数据库到mount状态
SQL> startup mount
ORACLE instance started.
Total System Global Area 4982833152 bytes
Fixed Size 2934600 bytes
Variable Size 2734688440 bytes
Database Buffers 2231369728 bytes
Redo Buffers 13840384 bytes
Database mounted.
5.限制session
SQL> alter system enable restricted session;
System altered.
6.查询相关参数并修改,防止有任务自动启动执行
SQL> show parameter job_queue_processes;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
job_queue_processes integer 1000
SQL> show parameter aq_tm_processes;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
aq_tm_processes integer 1
SQL> alter system set job_queue_processes=0;
System altered.
SQL> ALTER SYSTEM SET AQ_TM_PROCESSES=0;
System altered.
7.打开数据库
SQL> alter database open ;
Database altered.
8.修改字符集
SQL> alter database character set AL32UTF8;
alter database character set AL32UTF8
*
ERROR at line 1:
ORA-12712: new character set must be a superset of old character set
出现错误提示,新字符集必须是老字符集的超集,也就原来字符集是新字符集的子集,可以再Oracle官方文档上查询字符集包含关系。下面使用Oracle内部命令internal_use,跳过超集检查,生产环境不建议使用此方法。
SQL> alter database character set internal_use AL32UTF8;
Database altered.
9.查询当前字符集
SQL> select * from nls_database_parameters where parameter='NLS_CHARACTERSET';
PARAMETER VALUE
------------------------------------------------------------ ------------------------------------------------------------
NLS_CHARACTERSET AL32UTF8
10.关闭数据库
SQL> shutdown immediate
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
11.启动数据库到mount状态
SQL> startup mount
ORACLE instance started.
Total System Global Area 4982833152 bytes
Fixed Size 2934600 bytes
Variable Size 2734688440 bytes
Database Buffers 2231369728 bytes
Redo Buffers 13840384 bytes
Database mounted.
12.将相关参数改回原来值
SQL> alter system set job_queue_processes=1000;
System altered.
SQL> ALTER SYSTEM SET AQ_TM_PROCESSES=1;
System altered.
13.打开数据库
SQL> alter database open ;
Database altered.
原文地址: