修改数据库 Character Set

我在自己的笔记本上装了个Oracle XE (RedHat5),当时已经设置了环境变量 NLS_LANG=american_america.zhs16gbk
但不知为什么数据库启动后它的字符集还却是:american_america.we8mswin1252
我按照这篇文章
http://blog.csdn.net/tianlesoftware/archive/2009/12/01/4915223.aspx
里的 “修改Server端CharacterSet”,但是在执行
ALTER DATABASE CHARACTER SET ZHS16GBK;

时提示
ORA-12712: new character set must be a superset of old character set

后来查了很多资料,可以不理会这这个错误,可以路过超集的检查。
ALTER DATABASE character set INTERNAL_USE ZHS16GBK;


操作过程如下:
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 SESSION SET SQL_TRACE=TRUE;//语句跟踪
System altered.
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;

PARAMETER                                                        VALUE
---------------------------------------------------------------- ---------------
NLS_LANGUAGE                                                     AMERICAN
NLS_TERRITORY                                                    AMERICA
NLS_CURRENCY                                                     $
NLS_ISO_CURRENCY                                                 AMERICA
NLS_NUMERIC_CHARACTERS                                           .,
NLS_CALENDAR                                                     GREGORIAN
NLS_DATE_FORMAT                                                  DD-MON-RR
NLS_DATE_LANGUAGE                                                AMERICAN
NLS_CHARACTERSET                                                 ZHS16GBK
NLS_SORT                                                         BINARY
NLS_TIME_FORMAT                                                  HH.MI.SSXFF AM

PARAMETER                                                        VALUE
---------------------------------------------------------------- ---------------
NLS_TIMESTAMP_FORMAT                                             DD-MON-RR HH.MI
NLS_TIME_TZ_FORMAT                                               HH.MI.SSXFF AM
NLS_TIMESTAMP_TZ_FORMAT                                          DD-MON-RR HH.MI
NLS_DUAL_CURRENCY                                                $
NLS_NCHAR_CHARACTERSET                                           UTF8
NLS_COMP                                                         BINARY
NLS_LENGTH_SEMANTICS                                             BYTE
NLS_NCHAR_CONV_EXCP                                              FALSE

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;

PARAMETER                                                        VALUE
---------------------------------------------------------------- ---------------
NLS_LANGUAGE                                                     AMERICAN
NLS_TERRITORY                                                    AMERICA
NLS_CURRENCY                                                     $
NLS_ISO_CURRENCY                                                 AMERICA
NLS_NUMERIC_CHARACTERS                                           .,
NLS_CALENDAR                                                     GREGORIAN
NLS_DATE_FORMAT                                                  DD-MON-RR
NLS_DATE_LANGUAGE                                                AMERICAN
NLS_CHARACTERSET                                                 ZHS16GBK
NLS_SORT                                                         BINARY
NLS_TIME_FORMAT                                                  HH.MI.SSXFF AM

PARAMETER                                                        VALUE
---------------------------------------------------------------- ---------------
NLS_TIMESTAMP_FORMAT                                             DD-MON-RR HH.MI
NLS_TIME_TZ_FORMAT                                               HH.MI.SSXFF AM
NLS_TIMESTAMP_TZ_FORMAT                                          DD-MON-RR HH.MI
NLS_DUAL_CURRENCY                                                $
NLS_NCHAR_CHARACTERSET                                           UTF8
NLS_COMP                                                         BINARY
NLS_LENGTH_SEMANTICS                                             BYTE
NLS_NCHAR_CONV_EXCP                                              FALSE

19 rows selected.




另外,网上的很多文章都有个注意:
引用

在Oracle9i中,如果数据库存在CLOB类型字段,那么就不允许对字符集进行转换

对于不同情况,Oracle提供不同的解决方案,如果是用户数据表,一般我们可以把包含CLOB字段的表导出,然后drop掉相关对象,
转换后再导入数据库;对于系统表,可以按照以下方式处理:
SQL> truncate table Metastylesheet;

 Table truncated. 

你可能感兴趣的:(oracle,sql,.net,SQL Server,Blog)