本文主要是介绍ORACLE修改数据库字符集,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
修改数据库字符集
oracle11g 修改字符集 修改为ZHS16GBK
1.cmd下,cd到oracle数据库软件的服务器端 如:D:\app\Administrator\product\11.2.0\dbhome_1\BIN
2.输入set ORACLE_SID=你想进入的数据库的那个sid
3.输入 sqlplus /nolog
4.将数据库启动到RESTRICTED模式下做字符集更改:
SQL> conn /as sysdba
Connected.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 236000356 bytes
Fixed Size 451684 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.
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 ZHS16GBK;
ALTER DATABASE CHARACTER SET ZHS16GBK
*
ERROR at line 1:
ORA-12712: new character set must be a superset of old character set
提示我们的字符集:新字符集必须为旧字符集的超集,这时我们可以跳过超集的检查做更改:
SQL> ALTER DATABASE character set INTERNAL_USE ZHS16GBK;
Database altered.
SQL> select * from v$nls_parameters;
略
19 rows selected.
重启检查是否更改完成:
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 236000356 bytes
Fixed Size 451684 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.
Database opened.
SQL> select * from v$nls_parameters;
数据库字符集在创建后原则上不能更改。因此,在前期规划和安装之初考虑使用哪一种字符集十分重要。对数据库服务器而言,错误的修改字符集将会导致很多不可测的后果,可能会严重影响数据库的正常运行,所以在修改之前一定要确认两种字符集是否存在子集和超集的关系。一般来说,除非万不得已,我们不建议修改ORACLE数据库SERVER端的字符集。
有两种方法修改数据库字符集设置
1. 通常需要导出数据库数据,重建数据库,然后再导入数据库数据的方式来转换。
2. 通过ALTER DATABASE CHARACTER SET语句修改字符集,但创建数据库后可以修改的字符集是有限制的,只有新的字符集是当前字符集的超集时才能修改数据库字符集,例如UTF8是US7ASCII的超集,修改数据库字符集可使用ALTER DATABASE CHARACTER SET UTF8。
特别说明,我们最常用的两种字符集ZHS16GBK和ZHS16CGB231280之间不存在子集和超集关系,因此理论上讲这两种字符集之间的相互转换不受支持修改
关于数据库子集-超级对照表(subset-superset pairs),可以参考官方文档,例如ORACLE 10g的http://docs.oracle.com/cd/B19306_01/server.102/b14225/applocaledata.htm
Table A-11 Subset-Superset Pairs
Subset | Superset |
AR8ADOS710 | AR8ADOS710T |
AR8ADOS720 | AR8ADOS720T |
AR8ADOS720T | AR8ADOS720 |
AR8APTEC715 | AR8APTEC715T |
AR8ARABICMACT | AR8ARABICMAC |
AR8ISO8859P6 | AR8ASMO708PLUS |
AR8ISO8859P6 | AR8ASMO8X |
AR8MUSSAD768 | AR8MUSSAD768T |
AR8MUSSAD768T | AR8MUSSAD768 |
AR8NAFITHA711 | AR8NAFITHA711T |
AR8NAFITHA721 | AR8NAFITHA721T |
AR8SAKHR707 | AR8SAKHR707T |
AR8SAKHR707T | AR8SAKHR707 |
BLT8CP921 | BLT8ISO8859P13 |
BLT8CP921 | LT8MSWIN921 |
D7DEC | D7SIEMENS9780X |
D7SIEMENS9780X | D7DEC |
DK7SIEMENS9780X | N7SIEMENS9780X |
I7DEC | I7SIEMENS9780X |
I7SIEMENS9780X | IW8EBCDIC424 |
IW8EBCDIC424 | IW8EBCDIC1086 |
KO16KSC5601 | KO16MSWIN949 |
LT8MSWIN921 | BLT8ISO8859P13 |
LT8MSWIN921 | BLT8CP921 |
N7SIEMENS9780X | DK7SIEMENS9780X |
US7ASCII | See Table A-12, "US7ASCII Supersets". |
UTF8 | AL32UTF8 |
WE8DEC | TR8DEC |
WE8DEC | WE8NCR4970 |
WE8ISO8859P1 | WE8MSWIN1252 |
WE8ISO8859P9 | TR8MSWIN1254 |
WE8NCR4970 | TR8DEC |
WE8NCR4970 | WE8DEC |
WE8PC850 | WE8PC858 |
1: SQL>CONN / AS SYSDBA;
2:
3: SQL>SHUTDOWN IMMEDIATE;
4:
5: SQL>STARTUP MOUNT;
6:
7: SQL>ALTER SYSTEM ENABLE RESTRICTED SESSION;
8:
9: SQL>ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;
10:
11: SQL>ALTER SYSTEM SET AQ_TM_PROCESSES=0;
12:
13: SQL>ALTER DATABASE OPEN;
--可以从子集到父集
1: SQL>ALTER DATABASE CHARACTER SET ZHS16GBK;
2:
3: --如果是从父集到子集,需要使用INTERNAL_USE参数,跳过超子集检测
4:
5: SQL>ALTER DATABASE NATIONAL CHARACTER SET UTF8;
6:
7: --SQL>ALTER DATABASE NATIONAL CHARACTER SET INTERNAL_USE UTF8;
8:
9: SQL>SHUTDOWN IMMEDIATE;
10:
11: SQL>STARTUP;
ALTER DATABASE NATIONAL CHARACTER SET UTF8;
有可能会出现ORA-12717: Cannot ALTER DATABASE NATIONAL CHARACTER SET when NCLOB data exists 这样的提示信息.这时你用ALTER DATABASE NATIONAL CHARACTER SET INTERNAL_USE UTF8;就可解决上述问题。
这篇关于ORACLE修改数据库字符集的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!