sitemap

RSS地图

收藏本站

设为首页

Oracle研究中心

当前位置:Oracle研究中心 > 故障案例 >

【案例】Oracle 10G完美修改数据库字符集三种方法 详细操作过程

时间:2016-11-16 20:48   来源:Oracle研究中心   作者:网络   点击:

天萃荷净 Oracle研究中心案例分析:分享一篇关于Oracle 10G数据库修改数据库字符集的笔记,通过三种方法使用csalter、csscan等工具进行修改。

本站文章除注明转载外,均为本站原创: 转载自love wife & love life —Roger 的Oracle技术博客
本文链接地址: 10g中如何修改数据库字符集?

SQL> !uname -a
Linux roger 2.6.9-42.ELsmp #1 SMP Wed Jul 12 23:27:17 EDT 2006 i686 i686 i386 GNU/Linux

SQL> SELECT userenv('language') FROM dual;

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

SQL> SELECT * FROM v$version;

BANNER
----------------------------------------------------------------
Oracle DATABASE 10g Enterprise Edition Release 10.2.0.4.0 - Prod
PL/SQL Release 10.2.0.4.0 - Production
CORE    10.2.0.4.0      Production
TNS FOR Linux: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production

SQL> conn roger/roger
Connected.

SQL> CREATE TABLE ht01(id NUMBER,name varchar2(6));
TABLE created.

SQL> INSERT INTO ht01 VALUES(1,'中国');
1 ROW created.

SQL> INSERT INTO ht01 VALUES(2,'北京');     
1 ROW created.

SQL> commit;
Commit complete.

SQL> SELECT * FROM ht01;

        ID NAME
---------- ------
         1    
         2    


安装配置csscan

SQL> @ /rdbms/admin/csminst.SQL
GRANT READ ON directory log_file_dir TO system
                        *
ERROR at line 1:
ORA-22930: directory does NOT exist

GRANT READ ON directory data_file_dir TO system
                        *
ERROR at line 1:
ORA-22930: directory does NOT exist

DROP USER csmig cascade
          *
ERROR at line 1:
ORA-01918: USER 'CSMIG' does NOT exist

Please CREATE password FOR USER CSMIG:
Enter VALUE FOR csmig_passwd: csmig
OLD   1: CREATE USER csmig IDENTIFIED BY &csmig_passwd
NEW   1: CREATE USER csmig IDENTIFIED BY csmig

USER created.

GRANT succeeded.
GRANT succeeded.
GRANT succeeded.
GRANT succeeded.
GRANT succeeded.
GRANT succeeded.
GRANT succeeded.
GRANT succeeded.
GRANT succeeded.
GRANT succeeded.

USER altered.
1 ROW created.
1 ROW updated.
TABLE created.
DROP public synonym csm$parameters
                    *
ERROR at line 1:
ORA-01432: public synonym TO be dropped does NOT exist
Synonym created.

GRANT suOracleoracleplus.netcceeded.
TABLE created.
DROP public synonym csm$query
                    *
ERROR at line 1:
ORA-01432: public synonym TO be dropped does NOT exist
Synonym created.
GRANT succeeded.
TABLE created.
DROP public synonym csm$tables
                    *
ERROR at line 1:
ORA-01432: public synonym TO be dropped does NOT exist
Synonym created.
GRANT succeeded.
TABLE created.
DROP public synonym csm$columns
                    *
ERROR at line 1:
ORA-01432: public synonym TO be dropped does NOT exist
Synonym created.
GRANT succeeded.
TABLE created.
DROP public synonym csm$extables
                    *
ERROR at line 1:
ORA-01432: public synonym TO be dropped does NOT exist
Synonym created.
GRANT succeeded.
TABLE created.
DROP public synonym csm$errors
                    *
ERROR at line 1:
ORA-01432: public synonym TO be dropped does NOT exist

Synonym created.
GRANT succeeded.
TABLE created.
DROP public synonym csm$langid
                    *
ERROR at line 1:
ORA-01432: public synonym TO be dropped does NOT exist
Synonym created.
GRANT succeeded.
TABLE created.
DROP public synonym csm$charsetid
                    *
ERROR at line 1:
ORA-01432: public synonym TO be dropped does NOT exist
Synonym created.
GRANT succeeded.
TABLE created.
DROP public synonym csm$indexes
                    *
ERROR at line 1:
ORA-01432: public synonym TO be dropped does NOT exist
Synonym created.
GRANT succeeded.
TABLE created.
DROP public synonym csm$constraints
                    *
ERROR at line 1:
ORA-01432: public synonym TO be dropped does NOT exist
Synonym created.
GRANT succeeded.
TABLE created.
DROP public synonym csm$triggers
                    *
ERROR at line 1:
ORA-01432: public synonym TO be dropped does NOT exist
Synonym created.
GRANT succeeded.
TABLE created.
DROP public synonym csm$dictusers
                    *
ERROR at line 1:
ORA-01432: public synonym TO be dropped does NOT exist
Synonym created
GRANT succeeded.
14 ROWS created.
VIEW created.
DROP public synonym csmv$tables
                    *
ERROR at line 1:
ORA-01432: public synonym TO be dropped does NOT exist
Synonym created.
VIEW created.
DROP public synonym csmv$columns
                    *
ERROR at line 1:
ORA-01432: public synonym TO be dropped does NOT exist
Synonym created.
VIEW created
DROP public synonym csmv$errors
                    *
ERROR at line 1:
ORA-01432: public synonym TO be dropped does NOT exist
Synonym created.
VIEW created
DROP public synonym csmv$indexes
                    *
ERROR at line 1:
ORA-01432: public synonym TO be dropped does NOT exist
Synonym created.
VIEW created.
DROP public synonym csmv$constraints
                    *
ERROR at line 1:
ORA-01432: public synonym TO be dropped does NOT exist
Synonym created.
VIEW created.
DROP public synonym csmv$triggers
                    *
ERROR at line 1:
ORA-01432: public synonym TO be dropped does NOT exist
Synonym created
VIEW created.
VIEW created.
VIEW created.
VIEW created.
GRANT succeeded.
GRANT succeeded.
Commit complete.

Disconnected FROM Oracle DATABASE 10g Enterprise Edition Release 10.2.0.4.0 - Production
WITH the Partitioning, OLAP, DATA Mining AND REAL Application Testing options

从上面的安装结果输出信息来看,下面的2条授权语句执行失败了,

GRANT READ ON directory log_file_dir TO system
GRANT READ ON directory data_file_dir TO system

这两句授权的语句,是没什么用的,完全可以从scminst.sql脚本中删除,大家可以参考如下metalink文档:

Installing and configuring Csscan in 10g and 11g (Database Character Set Scanner) [ID 745809.1]

关于csscan的运用,大家可以查看帮助信息,可以进行全库,用户等级别的扫描,我这里使用全库扫描

[oracle@roger ~]$ csscan system/oracle FULL=y FROMCHAR=WE8ISO8859P1 TOCHAR=ZHS16GBK ARRAY=1024000 PROCESS=1

CHARACTER SET Scanner v2.1 : Release 10.2.0.3.0 - Production ON Mon Jul 4 16:29:41 2011
Copyright (c) 1982, 2007, Oracle.  ALL rights reserved.

Connected TO:
Oracle DATABASE 10g Enterprise Edition Release 10.2.0.4.0 - Production
WITH the Partitioning, OLAP, DATA Mining AND REAL Application Testing options

Enumerating TABLES TO scan...
. process 1 scanning SYS.SOURCE$[AAAABIAABAAAAIRAAA]
. process 1 scanning SYS.METHOD$[AAAAC1AABAAAAURAAA]
. process 1 scanning SYS.TYPE$[AAAAC1AABAAAAURAAA]
. process 1 scanning SYS.PARAMETER$[AAAAC1AABAAAAURAAA]
. process 1 scanning SYS.ATTRIBUTE$[AAAAC1AABAAAAURAAA]
. process 1 scanning SYS.TAB$[AAAAACAABAAAAAZAAA]
. process 1 scanning SYS.ARGUMENT$[AAAABHAABAAAAIJAAA]
. process 1 scanning SYS.LIBRARY$[AAAAACAABAAAAAZAAA]
. process 1 scanning SYS.NTAB$[AAAAACAABAAAAAZAAA]
. process 1 scanning SYS.VIEWTRCOL$[AAAAACAABAAAAAZAAA]
. process 1 scanning SYS.TYPE_MISC$[AAAAACAABAAAAAZAAA]
. process 1 scanning SYS.IND$[AAAAACAABAAAAAZAAA]
. process 1 scanning SYS.CLU$[AAAAACAABAAAAAZAAA]
. process 1 scanning SYS.OPQTYPE$[AAAAACAABAAAAAZAAA]
. process 1 scanning SYS.COL$[AAAAACAABAAAAAZAAA]
. process 1 scanning SYS.ICOL$[AAAAACAABAAAAAZAAA]
. process 1 scanning SYS.LOB$[AAAAACAABAAAAAZAAA]
. process 1 scanning SYS.ATTRCOL$[AAAAACAABAAAAAZAAA]
. process 1 scanning SYS.OBJ$[AAAAASAABAAAAB5AAA]
. process 1 scanning SYS.VIEW$[AAAAA/AABAAAAHJAAA]
. process 1 scanning SYS.HISTGRM$[AAAAD7AABAAAAcJAAA]
. process 1 scanning MDSYS.SDO_CS_SRS[AAAMAAAADAAADcRAAA]
. process 1 scanning SYS.JAVASNM$[AAAAGHAABAAAAvZAAA]
. process 1 scanning MDSYS.SDO_COORD_REF_SYS[AAALVOAADAAADfJAAA]
. process 1 scanning SYS.SETTINGS$[AAAABQAABAAAAJRAAA]
. process 1 scanning SYS.IDL_CHAR$[AAAABKAABAAAAIhAAA]
. process 1 scanning SYS.SYS$SERVICE_METRICS_TAB[AAACZYAADAAABVhAAA]
. process 1 scanning SYS.SYN$[AAAAA+AABAAAAHBAAA]
. process 1 scanning SYS.WRH$_SQL_PLAN[AAACMpAADAAAAvJAAA]
. process 1 scanning SYS.PROCEDUREINFO$[AAAABGAABAAAAIBAAA]
. process 1 scanning SYS.CDEF$[AAAAAdAABAAAACxAAA]
. process 1 scanning SYS.COM$[AAAABhAABAAAALZAAA]
. process 1 scanning SYS.METASCRIPTFILTER$[AAAAH0AABAAAA95AAA]
. process 1 scanning SYS.CCOL$[AAAAAdAABAAAACxAAA]
. process 1 scanning XDB.XDB$ELEMENT[AAAKP5AADAAACqZAAA]
. process 1 scanning SYS.WRH$_SQLSTAT[AAAMnXAADAAAAsJAAA]
. process 1 scanning SYS.WRI$_OPTSTAT_HISTHEAD_HISTORY[AAABB+AADAAAAUhAAA]
. process 1 scanning SYS.AW_OBJ$[AAAAJLAADAAAAAJAAA]
. process 1 scanning MDSYS.SDO_COORD_OPS[AAALVWAADAAADgBAAA]
. process 1 scanning MDSYS.SDO_COORD_OP_PARAM_VALS[AAALVgAADAAADg5AAA]
. process 1 scanning SYS.TRIGGER$[AAAABRAABAAAAJZAAA]
. process 1 scanning SYS.METAFILTER$[AAAAHpAABAAAA8hAAA]
. process 1 scanning SYS.WRH$_SQLTEXT[AAACMjAADAAAAuZAAA]
. process 1 scanning SYS.METANAMETRANS$[AAAAH3AABAAAA+RAAA]
. process 1 scanning SYS.JAVAOBJ$[AAAABOAABAAAAJBAAA]
. process 1 scanning XDB.XDB$COMPLEX_TYPE[AAAKLvAADAAACJJAAA]
. process 1 scanning SYS.WRH$_PARAMETER[AAAMoFAADAAAA1RAAA]
. process 1 scanning SYS.PROCEDUREJAVA$[AAAAFGAABAAAAopAAA]
. process 1 scanning SYS.PROCEDURE$[AAAABFAABAAAAH5AAA]
. process 1 scanning SYS.METASTYLESHEET[AAAAHuAABAAAA9JAAA]
. process 1 scanning SYS.CON$[AAAAAcAABAAAACpAAA]
. process 1 scanning SYS.VTABLE$[AAAAFuAABAAAAsxAAA]
. process 1 scanning SYSMAN.MGMT_JOB_STEP_PARAMS[AAAMWOAADAAAGV5AAA]
. process 1 scanning SYS.T1[AAAMprAABAAAO6JAAA]
. process 1 scanning XDB.XDB$SCHEMA[AAAKR3AADAAAC6JAAA]
. process 1 scanning SYS.AW$AWMD[AAALc3AADAAAEJZAAA]
. process 1 scanning SYS.WRH$_ROWCACHE_SUMMARY[AAAMn5AADAAAAzRAAA]
. process 1 scanning SYSMAN.MGMT_POLICY_RULE[AAAMVNAADAAAAt5AAA]
. process 1 scanning SYS.WRI$_OPTSTAT_HISTGRM_HISTORY[AAABCBAADAAAAU5AAA]
. process 1 scanning SYS.WRH$_SQL_BIND_METADATA[AAACMtAADAAAAvpAAA]
. process 1 scanning SYS.WRI$_OPTSTAT_IND_HISTORY[AAABB7AADAAAAUJAAA]
. process 1 scanning XDB.XDB$ATTRIBUTE[AAAKQPAADAAACtJAAA]
. process 1 scanning SYSMAN.MGMT_ECM_SNAPSHOT_MD_COLUMNS[AAAMTgAADAAAGAZAAA]
. process 1 scanning XDB.XDB$SIMPLE_TYPE[AAAKJhAADAAAB3ZAAA]
. process 1 scanning SYS.WRH$_EVENT_NAME[AAACM3AADAAAAwpAAA]
. process 1 scanning SYS.METAPATHMAP$[AAAAH6AABAAAA+pAAA]
. process 1 scanning SYSMAN.MGMT_SYSTEM_PERFORMANCE_LOG[AAAMX/AADAAAGj5AAA]
. process 1 scanning SYSMAN.MGMT_JOB_EXECPLAN[AAAMWMAADAAAGVpAAA]
. process 1 scanning XDB.XDB$SEQUENCE_MODEL[AAAKPhAADAAACnZAAA]
. process 1 scanning SYS.WRH$_PARAMETER_NAME[AAACOnAADAAAAypAAA]
. process 1 scanning MDSYS.SDO_DATUMS[AAALVGAADAAADeJAAA]
. process 1 scanning SYS.ERROR$[AAAABPAABAAAAJJAAA]
. process 1 scanning SYS.PENDING_SUB_SESSIONS$[AAAACWAABAAAARZAAA]
. process 1 scanning SYS.VIEWCON$[AAAADPAABAAAAWhAAA]
. process 1 scanning SYS.DEFSUBPART$[AAAAExAABAAAAmRAAA]
. process 1 scanning SYS.NOEXP$[AAAAFDAABAAAAoRAAA]
. process 1 scanning SYS.DIMLEVEL$[AAAAGnAABAAAAzZAAA]
. process 1 scanning SYS.DIMATTR$[AAAAGvAABAAAA0ZAAA]
. process 1 scanning SYS.HIERLEVEL$[AAAAG0AABAAAA1BAAA]
. process 1 scanning SYS.CONTEXT$[AAAAG/AABAAAA2ZAAA]
. process 1 scanning SYS.LOG$[AAAAImAABAAABERAAA]
. process 1 scanning SYS.AUX_STATS$[AAAAI8AABAAABG5AAA]
. process 1 scanning SYS.MAP_FILE_EXTENT$[AAAAJYAABAAABIpAAA]
. process 1 scanning SYS.MAP_EXTELEMENT$[AAAAJbAABAAABJBAAA]
. process 1 scanning SYS.STREAMS$_CAPTURE_PROCESS[AAAAJfAABAAABJRAAA]
. process 1 scanning SYS.STREAMS$_PROCESS_PARAMS[AAAAJqAABAAABKhAAA]
. process 1 scanning SYS.RESOURCE_PLAN$[AAAAMhAABAAABbJAAA]
. process 1 scanning SYS.REGISTRY$[AAAAN8AABAAABexAAA]
. process 1 scanning SYS.REGISTRY$SCHEMAS[AAAAN+AABAAABfBAAA]
. process 1 scanning SYS.AUDIT_ACTIONS[AAAArrAABAAABnhAAA]
. process 1 scanning SYSTEM.MVIEW$_ADV_BASETABLE[AAAA5DAABAAABr5AAA]
. process 1 scanning SYSTEM.MVIEW$_ADV_JOURNAL[AAAA5lAABAAAB0RAAA]
. process 1 scanning SYSTEM.MVIEW$_ADV_PLAN[AAAA5nAABAAAB0hAAA]
. process 1 scanning SYS.DBMS_LOCK_ALLOCATED[AAABEpAABAAACKxAAA]
. process 1 scanning SYS.DBMS_ALERT_INFO[AAABEuAABAAACLBAAA]
. process 1 scanning SYS.ATTRIBUTE_TRANSFORMATIONS$[AAABFjAABAAACMBAAA]
. process 1 scanning SYS.REC_TAB$[AAABGJAABAAACQxAAA]
. process 1 scanning SYSTEM.DEF$_LOB[AAABNGAABAAACnRAAA]
. process 1 scanning SYSTEM.DEF$_PUSHED_TRANSACTIONS[AAABNcAABAAACppAAA]
. process 1 scanning SYS.SCHEDULER$_PROGRAM[AAABPkAABAAACqZAAA]
. process 1 scanning SYS.SCHEDULER$_JOBQTAB[AAABPyAABAAACrBAAA]
. process 1 scanning SYS.LOGMNRG_SEED$[AAABX8AABAAADJJAAA]
. process 1 scanning SYS.LOGMNRG_TS$[AAABYCAABAAADJ5AAA]
. process 1 scanning SYSTEM.REPCAT$_AUDIT_ATTRIBUTE[AAAB9YAABAAAEaZAAA]
. process 1 scanning SYSTEM.REPCAT$_TEMPLATE_TYPES[AAAB+IAABAAAEcBAAA]
. process 1 scanning SYSTEM.REPCAT$_TEMPLATE_REFGROUPS[AAAB+hAABAAAEdZAAA]
. process 1 scanning SYSTEM.REPCAT$_RUNTIME_PARMS[AAAB/eAABAAAEhJAAA]
. process 1 scanning SYSTEM.REPCAT$_INSTANTIATION_DDL[AAAB/wAABAAAEihAAA]
. process 1 scanning SYSTEM.REPCAT$_SITES_NEW[AAAB/4AABAAAEjZAAA]
. process 1 scanning SYS.HS$_BASE_DD[AAACF7AABAAAFGxAAA]
. process 1 scanning SYS.AURORA$STARTUP$CLASSES$[AAAJHJAABAAAKyRAAA]
. process 1 scanning SYS.EPG$_AUTH[AAAKZNAABAAAMLpAAA]
. process 1 scanning SYS.OLAP_OLEDB_FUNCTIONS_PVT[AAAL/SAABAAANGBAAA]
. process 1 scanning SYS.APPLY$_ERROR[AAAAKVAADAAAABxAAA]
. process 1 scanning SYS.DIR$NODE_ATTRIBUTES[AAAAMTAADAAAAIJAAA]
. process 1 scanning SYS.WRI$_ADV_SQLW_TABVOL[AAAA6xAADAAAARpAAA]
. process 1 scanning SYS.SCHEDULER$_WINDOW_DETAILS[AAABQvAADAAAAXRAAA]
. process 1 scanning SYSTEM.LOGSTDBY$PLSQL[AAAB2EAADAAAAlZAAA]
. process 1 scanning SYS.WRH$_COMP_IOSTAT[AAACMYAADAAAAtZAAA]
. process 1 scanning SYS.WRH$_OSSTAT_NAME[AAACOlAADAAAA7ZAAA]
. process 1 scanning SYS.WRH$_DLM_MISC_BL[AAACPDAADAAAA+pAAA]
. process 1 scanning SYS.WRH$_BUFFERED_QUEUES[AAACP0AADAAABDhAAA]
. process 1 scanning DBSNMP.MGMT_SNAPSHOT_SQL[AAACX7AADAAABSZAAA]
. process 1 scanning WMSYS.WM$VERSIONED_TABLES_UNDO_CODE[AAACapAADAAABchAAA]
. process 1 scanning WMSYS.WM$CONSTRAINTS_TABLE[AAACf1AADAAABkxAAA]
. process 1 scanning ORDSYS.SI_VALUES_TAB[AAAKcrAADAAADZpAAA]
. process 1 scanning XDB.Folder23_TAB[AAAKWQAADAAADIpAAA]
ORA-00904: "SYS_NC00011$": invalid identifier
CSS-00144: failed TO scan TABLE XDB.Folder23_TAB
. process 1 scanning ORDSYS.SI_IMAGE_FORMATS_TAB[AAAKcnAADAAADZJAAA]
......省略部分内容
. process 1 scanning SYS.STREAMS$_APPLY_SPILL_MSGS_PART[AAABezAADAAAAjRAAA]
. process 1 scanning SYS.WRH$_TABLESPACE_STAT[AAAMnAAADAAABQpAAA]

Creating DATABASE Scan Summary Report...
Creating Individual Exception Report...
Scanner TERMINATED successfully.

[oracle@roger ~]$
scan默认会将扫描相关的信息写入到一个试图scm$parameters中,查询如下:

SQL> SELECT * FROM csm$parameters;
NAME                           VALUE
------------------------------ --------------------------------------------------
SCANNER_VERSION                5
SCAN_TYPE                      ALL
SCAN_CHAR                      YES
TO_CHARSET_NAME                ZHS16GBK
FROM_CHARSET_NAME              WE8ISO8859P1
SCAN_NCHAR                     NO
MAX_ARRAY_SIZE                 1024000
MAX_ROWS_IN_HEAP               100
NUMBER_OF_PROCESS              1
SUPPRESS_ERROR_LOG_BY          -1
INSERT_SUPPRESSED              NO
CAPTURE_CONVERTIBLE_DATA       NO
SCANNER_SCRIPT                 NO
SCANNER_PRESERVE               NO
MIGRATE_TO_SUPERSET            0
CSLD_ENABLE                    0
PREVIOUS_CHARACTER_SET         WE8ISO8859P1
PREVIOUS_NCHAR_SET             AL16UTF16
TIME_START                     2011-07-04 16:29:44
TIME_END                       2011-07-04 16:32:44

20 ROWS selected.

另外补充一下的是,scan默认也会生成几个scan扫描的结果文件,如下:

[oracle@roger ~]$ ls -ltr scan*
-rwxrwxrwx  1 oracle dba   444 Nov 28  2010 scan.sh
-rw-r--r--  1 oracle dba  8239 Jul  4 16:32 scan.txt
-rw-r--r--  1 oracle dba 75329 Jul  4 16:32 scan.out
-rw-r--r--  1 oracle dba  1878 Jul  4 16:32 scan.err
[oracle@roger ~]$ cat scan.err
DATABASE Scan Individual Exception Report

[DATABASE Scan Parameters]
Parameter                      VALUE                                         
------------------------------ ------------------------------------------------
CSSCAN Version                 v2.1                                          
Instance Name                  roger                                         
DATABASE Version               10.2.0.4.0                                    
Scan TYPE                      FULL DATABASE                                 
Scan CHAR DATA                 YES                                           
DATABASE CHARACTER SET         WE8ISO8859P1                                  
FROMCHAR                       WE8ISO8859P1                                  
TOCHAR                         ZHS16GBK                                      
Scan NCHAR DATA                NO                                            
Array fetch buffer SIZE        1024000                                       
NUMBER OF processes            1                                             
Capture convertible DATA       NO                                            
------------------------------ ------------------------------------------------

[DATA Dictionary individual exceptions]
[Application DATA individual exceptions]
USER  : ROGER
TABLE : HT01
COLUMN: NAME
TYPE  : VARCHAR2(6)
NUMBER OF Exceptions         : 2       
MAX Post Conversion DATA SIZE: 8       

ROWID              Exception TYPE      SIZE Cell DATA(FIRST 30 bytes)   
------------------ ------------------ ----- ------------------------------
AAAMrNAAFAAAAAMAAA exceed COLUMN SIZE     8 靠靠                        
AAAMrNAAFAAAAAMAAB exceed COLUMN SIZE     8 靠靠                        
------------------ ------------------ ----- ------------------------------

10g 中如何修改字符集?

对于oracle10g,已经完全跟8i 9i不一样了,不再使用alter database 命令,metalink解释如下:
Using the “ALTER DATABASE CHARACTER SET” command in 8i or 9i and CSALTER in 10g and up.
首先我们来看下scan.txt的内容:

[Scan Summary]

All character type data in the data dictionary are convertible to the new character set
All character type application data are convertible to the new character set

[Data Dictionary Conversion Summary]

Datatype                    Changeless      Convertible       Truncation            Lossy
--------------------- ---------------- ---------------- ---------------- ----------------
VARCHAR2                     1,922,959                0                0                0
CHAR                             1,104                0                0                0
LONG                           146,008                0                0                0
CLOB                            22,544            1,215                0                0
VARRAY                              24                0                0                0
--------------------- ---------------- ---------------- ---------------- ----------------
Total                        2,092,639            1,215                0                0
Total in percentage             99.942%           0.058%           0.000%           0.000%

The data dictionary can be safely migrated using the CSALTER script

[Application Data Conversion Summary]

Datatype                    Changeless      Convertible       Truncation            Lossy
--------------------- ---------------- ---------------- ---------------- ----------------
VARCHAR2                        28,702                2                0                0
CHAR                                 0                0                0                0
LONG                                 0                0                0                0
CLOB                                 0                0                0                0
VARRAY                           1,575                0                0                0
--------------------- ---------------- ---------------- ---------------- ----------------
Total                           30,277                2                0                0
Total in percentage             99.993%           0.007%           0.000%           0.000%

[Distribution of Convertible, Truncated and Lossy Data by Table]

USER.TABLE                                              Convertible       Truncation            Lossy
-------------------------------------------------- ---------------- ---------------- ----------------
MDSYS.SDO_COORD_OP_PARAM_VALS                                   200                0                0
MDSYS.SDO_GEOR_XMLSCHEMA_TABLE                                    1                0                0
MDSYS.SDO_STYLES_TABLE                                           78                0                0
MDSYS.SDO_XML_SCHEMAS                                             3                0                0
ROGER.HT01                                                        2                0                0
SYS.METASTYLESHEET                                               80                0                0
SYS.RULE$                                                         1                0                0
SYS.WRH$_SQLTEXT                                                381                0                0
SYS.WRH$_SQL_PLAN                                               347                0                0
SYS.WRI$_DBU_FEATURE_METADATA                                    98                0                0
SYS.WRI$_DBU_FEATURE_USAGE                                        7                0                0
SYS.WRI$_DBU_HWM_METADATA                                        19                0                0
-------------------------------------------------- ---------------- ---------------- ----------------

[Distribution of Convertible, Truncated and Lossy Data by Column]

USER.TABLE|COLUMN                                       Convertible       Truncation            Lossy
-------------------------------------------------- ---------------- ---------------- ----------------
MDSYS.SDO_COORD_OP_PARAM_VALS|PARAM_VALUE_FILE                  200                0                0
MDSYS.SDO_GEOR_XMLSCHEMA_TABLE|XMLSCHEMA                          1                0                0
MDSYS.SDO_STYLES_TABLE|DEFINITION                                78                0                0
MDSYS.SDO_XML_SCHEMAS|XMLSCHEMA                                   3                0                0
ROGER.HT01|NAME                                                   2                0                0
SYS.METASTYLESHEET|STYLESHEET                                    80                0                0
SYS.RULE$|CONDITION                                               1                0                0
SYS.WRH$_SQLTEXT|SQL_TEXT                                       381                0                0
SYS.WRH$_SQL_PLAN|OTHER_XML                                     347                0                0
SYS.WRI$_DBU_FEATURE_METADATA|INST_CHK_LOGIC                     12                0                0
SYS.WRI$_DBU_FEATURE_METADATA|USG_DET_LOGIC                      86                0                0
SYS.WRI$_DBU_FEATURE_USAGE|FEATURE_INFO                           7                0                0
SYS.WRI$_DBU_HWM_METADATA|LOGIC                                  19                0                0
-------------------------------------------------- ---------------- ---------------- ----------------

[Indexes to be Rebuilt]

USER.INDEX on USER.TABLE(COLUMN)

对于Convertible, Truncated 的对象,我们可以使用exp或expdp导出,然后drop原表,等字符集修改完以后再进行导入。
另外对于lossy的对象,我们可以借助plsql等工具将数据导出,然后手工转换编码。

关于cscan工具扫描以后产生的结果,如何去阅读的问题,以及在10g以后版本中如何安装的问题;

大家可以参考如下两篇文章:
Installing and configuring Csscan in 10g and 11g (Database Character Set Scanner) [ID 745809.1]
Csscan output explained [ID 444701.1]。

10g 以前的版本可以参考下面的文档:
Installing and Configuring Csscan in 8i and 9i (Database Character Set Scanner) [ID 458122.1]

ok 我们继续,由于前面scan的结果中有[Distribution of Convertible, Truncated and Lossy Data by Table],
所以我们需要先将这部分表进行导出,不然直接进行字符集的转换肯定会不成功,如下:

SQL> @  /rdbms/admin/csalter.plb

0 ROWS created.
FUNCTION created.
FUNCTION created.
PROCEDURE created.
This script will UPDATE the content OF the Oracle DATA Dictionary.
Please ensure you have a FULL backup BEFORE initiating this PROCEDURE.
Would you LIKE TO proceed (Y/N) y
OLD   6:     IF (UPPER('&conf') <> 'Y') THEN
NEW   6:     IF (UPPER('y') <> 'Y') THEN
Checking DATA validility...
Sorry ONLY one SESSION IS allowed TO run this script
PL/SQL PROCEDURE successfully completed.
Checking OR Converting phrase did NOT finish successfully
No DATABASE (NATIONAL) CHARACTER SET will be altered
CSALTER finished unsuccessfully.
PL/SQL PROCEDURE successfully completed.
0 ROWS deleted.
FUNCTION dropped.
FUNCTION dropped.
PROCEDURE dropped.

1. 将scan.txt中所列出的部分表进行导出;
EXP system/oracle file=EXP.dmp TABLES=(MDSYS.SDO_COORD_OP_PARAM_VALS,MDSYS.SDO_GEOR_XMLSCHEMA_TABLE,MDSYS.SDO_STYLES_TABLE,MDSYS.SDO_XML_SCHEMAS       
,ROGER.HT01,SYS.METASTYLESHEET,SYS.RULE$,SYS.WRH$_SQLTEXT,SYS.WRH$_SQL_PLAN,SYS.WRI$_DBU_FEATURE_METADATA ,SYS.WRI$_DBU_FEATURE_USAGE
,SYS.WRI$_DBU_HWM_METADATA) buffer=1000000 log=EXP.log 

2. 在原库中删除该部分对象;
SQL> DROP TABLE MDSYS.SDO_COORD_OP_PARAM_VALS;
DROP TABLE MDSYS.SDO_GEOR_XMLSCHEMA_TABLE;
DROP TABLE MDSYS.SDO_STYLES_TABLE;      
DROP TABLE MDSYS.SDO_XML_SCHEMAS;        
DROP TABLE ROGER.HT01;                   
DROP TABLE SYS.METASTYLESHEET;           
DROP TABLE SYS.RULE$;                    
DROP TABLE SYS.WRH$_SQLTEXT;             
DROP TABLE SYS.WRH$_SQL_PLAN;            
DROP TABLE SYS.WRI$_DBU_FEATURE_METADATA;
DROP TABLE SYS.WRI$_DBU_FEATURE_USAGE;   
DROP TABLE SYS.WRI$_DBU_HWM_METADATA;

TABLE dropped.

TABLE dropped.

3. 运行csalter修改数据库字符集;

SQL> @  /rdbms/admin/csalter.plb;

0 ROWS created.
FUNCTION created.
FUNCTION created.
PROCEDURE created.

This script will UPDATE the content OF the Oracle DATA Dictionary.
Please ensure you have a FULL backup BEFORE initiating this PROCEDURE.
Would you LIKE TO proceed (Y/N) Y
OLD   6:     IF (UPPER('&conf') <> 'Y') THEN
NEW   6:     IF (UPPER('Y') <> 'Y') THEN
Checking DATA validility...
BEGIN converting system objects

PL/SQL PROCEDURE successfully completed.

ALTER the DATABASE CHARACTER SET...
CSALTER operation completed, please restart DATABASE   ---操作完成,需要重启数据库

PL/SQL PROCEDURE successfully completed.

0 ROWS deleted.
FUNCTION dropped.
FUNCTION dropped.
PROCEDURE dropped.

SQL> shutdown immediate;
DATABASE closed.
DATABASE dismounted.
ORACLE instance shut down.

SQL> startup

ORACLE instance started.
Total System Global Area  230686720 bytes
Fixed SIZE                  1266776 bytes
Variable SIZE             150997928 bytes
DATABASE Buffers           75497472 bytes
Redo Buffers                2924544 bytes
DATABASE mounted.
DATABASE opened.

SQL> SELECT userenv('language') FROM dual;

USERENV('LANGUAGE')
----------------------------------------------------
AMERICAN_AMERICA.ZHS16GBK
补充一个自己写的简单方案:

我们知道在oracle 10g以前版本,可以通过alter database Character set命令方式来直接修改数据库字符集,
但是从oracle10g版本开始,oracle不推荐这样使用,风险很大。

10g 版本,oracle提供了csalter工具进行修改,步骤如下:

一、 对数据库进行全备,可以进行逻辑导出全备或rman全备(记得同时备份参数文件,密码文件以及controlfile);
二、 安装配置csscan工具;用具有dba权限的用户执行 @ /rdbms/admin/csminst.sql;
三、 运行csscan进行扫描;


例如:
csscan system/oracle full=y FROMCHAR=WE8ISO8859P1 TOCHAR=ZHS16GBK ARRAY=1024000 PROCESS=1

可以csscan help=y查看帮助

Csscan运行结束后,默认会在当前目前下生存如下3个文件:

[oracle@roger oracle]$ ls -ltr scan*
-rw-r--r--  1 oracle dba  8239 Jul  4 16:56 scan.txt
-rw-r--r--  1 oracle dba 73078 Jul  4 16:56 scan.out
-rw-r--r--  1 oracle dba  1878 Jul  4 16:56 scan.err

Scan工具会把最近一次扫描的参数写入到同义词csm$parameters中,下次进行数据库字符集转换时,直接从该同义词读取信息;

检查scan.txt:
对于convertible, truncated的对象可以通过exp/imp来完成;
对于lossy的对象,可以用plsql进行导出然后手工转换编码,然后删除对象,等运行csalter命令修改字符集完成后,再将前面的对象导入。

导出convetitble和truncate的对象后,需要重新运行csscan工具;

四、 运行csalter修改字符集;

对于RAC环境:

1. 修改CLUSTER_DATABASE参数为flase;

Alter system set cluster_database=flase scope=spfile;
Alter system set job_queue_processes=0 scope=spfile;
alter system set aq_tm_processes=0 scope=spfile;

2. 启动数据库到单实例模式;
startup restrict
spool switch.log

3. 运行csalter:
—- 以sys执行: @ /rdbms/admin/csalter.plb
—- 检查执行csalter的输出信息,是否有错误;

如果执行那么修改还原原始的参数:
Alter system set cluster_database=true scope=spfile;
Alter system set job_queue_processes=old_value scope=both sid=’*';
alter system set aq_tm_processes=old_value scope=both sid=’*';

五、 重启数据库;

—-shutdown immediate;
—-startup
—-检查字符集是否修改成功
检查alert log或运行如下sql:
select userenv(‘language’) from dual;

六、 启动另外节点,检查clsuter状态。

七、 检查应用是否正常。

--------------------------------------ORACLE-DBA----------------------------------------

最权威、专业的Oracle案例资源汇总之【案例】Oracle 10G完美修改数据库字符集三种方法 详细操作过程

本文由大师惜分飞原创分享,网址:http://www.oracleplus.net/arch/1282.html

Oracle研究中心

关键词:

oracle csalter工具进行修改字符集

安装配置csscan教程

10g 中如何修改字符集