oracle 字符集 AL32UTF8、UTF8

林堯彬發表於2018-01-16
 簡介:ORACLE資料庫字符集,即Oracle全球化支援(Globalization Support),或即國家語言支援(NLS)其作用是用本國語言和格式來儲存、處理和檢索資料。利用全球化支援,ORACLE為使用者提供自己熟悉的資料庫母語環境,諸如日期格式、數字格式和儲存序列等。Oracle可以支援多種語言及字符集,其中oracle8i支援48種語言、76個國家地域、229種字符集,而oracle9i則支援57種語言、88個國家地域、235種字符集。由於oracle字符集種類多,且在儲存、檢索、遷移oracle資料時多個環節與字符集的設定密切相關,因此在實際的應用中,資料庫開發和管理人員經常會遇到有關oracle字符集方面的問題。

       字符集,實質就是按照一定的字元編碼方案,對一組特定的符號,分別賦予不同數值編碼的集合。Oracle資料庫最早支援的編碼方案是US7ASCII。Oracle的字符集命名遵循以下命名規則:<Language><bitsize><encoding>   即:  <語言><位元位數><編碼> 。比如: AL32UTF8表示:AL,代表all,指使用所有語言;32,,32位;UTF8編碼。檢視環境變數發現:NLS_LANG=American_America.AL32UTF8,American表示語言;America表示地區;AL32UTF8字符集型別。

         AL32UTF8和UTF8有什麼區別呢?Oracle的UTF8字符集由來已久,至少在8的時候就已經存在了,而對應的是UNICODE 3.0。而AL32UTF8字符集是9i才出現的,其對應的是UNICODE 5.0。這兩種字符集的區別在於,UNICODE 5.0與3.0相比,又增加了一些新的補充字元。但是在實際當中,使用到這些新增字元的可能性非常小,因此絕大部分情況下,選擇UTF8也是足夠的。AL32UTF8字符集是9i才出現的,那麼對於9i以後的版本訪問沒有任何問題,但是對於8i及以前的版本,則不認識這個字符集。這就使得8i及更低版本的客戶端在訪問9i以上AL32UTF8的資料庫時,會碰到各種各樣的問題。因此,如果資料庫版本都在9i及其以上,不需要考慮ORACLE8的資料庫,建議使用AL32UTF8字符集,它採用的Unicode標準要比UTF8採用的Unicode標準更新,支援的字元也更多一些。如果要考慮ORACLE8資料庫,建議使用UTF8字符集,它的相容性好,在ORACLE8及8I資料庫上使用AL32UTF8字符集容易出現問題。隨著現在版本11g逐漸開始稱為主流版本,8i客戶端的情況已經越來越少見了,因此在11.2的DBCA中,UTF8已經不是推薦字符集列表中的一員了。我們在遇到不相容的問題時就要修改字符集。AL32UTF8-->UTF8修改字符集的步驟:

shutdown immediate;     //關閉資料庫伺服器
startup mount;
alter session set sql_trace=true;
alter system enable restricted session;
alter system set job_queue_processes=0;
alter system set aq_tm_processes=0;
alter database open;
alter database character set internal_use utf8;
alter session set sql_trace=false;
shutdown immediate;
startup;

下面是別人的一個例項:

#su - oracle

$sqlplus "/ as sysdba"

SQL*Plus: Release11.2.0.3.0 Production on Wed Apr 18 14:40:10 2012
Copyright (c) 1982, 2011, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options

SQL>

修改之前的字符集
SQL> select * fromv$nls_parameters where parameter='NLS_CHARACTERSET';
 
PARAMETER                      VALUE
----------------- ----------------------------
NLS_CHARACTERSET               AL32UTF8
 
SQL>

開始修改
SQL> shutdownimmediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area 1603411968 bytes
FixedSize                 2226912 bytes
VariableSize            402654496 bytes
Database Buffers         1191182336bytes
RedoBuffers               7348224 bytes
Database mounted.
SQL> alter session setsql_trace=true;     

Session altered.

SQL> alter systemenable restricted session;

System altered.

SQL> show parameterjob_queue_process

NAME                                TYPE        VALUE
------------------------------------ ----------- ------------------------------
job_queue_processes                 integer     1000
SQL> alter system setjob_queue_processes=0;

System altered.

SQL> show parameteraq_tm_processes

NAME                                TYPE        VALUE
------------------------------------ ----------- ------------------------------
aq_tm_processes                     integer     0
SQL> alter databaseopen;

Database altered.

SQL> alter databasecharacter set internal_use utf8;

Database altered.

SQL> alter session setsql_trace=false;

Session altered.

SQL> shutdownimmediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area 1603411968 bytes
FixedSize                 2226912 bytes
VariableSize            402654496 bytes
Database Buffers         1191182336bytes
Redo Buffers               7348224 bytes
Database mounted.
Database opened.
SQL>

修改之後的字符集
SQL> select * fromv$nls_parameters where parameter='NLS_CHARACTERSET';
PARAMETER                      VALUE
----------------- ----------------------------
NLS_CHARACTERSET               UTF8
 
SQL>

 

--------end-------

 

有關oracle字符集的知識點可以參看下面兩篇帖子:

http://blog.csdn.net/robinson_0612/article/details/6030398

http://blog.163.com/zhyang@yeah/blog/static/130143844200991535913471/?fromdm&fromSearch&isFromSearchEngine=yes

轉載於:https://www.cnblogs.com/wangfengju/archive/2013/04/03/6173224.html

相關文章