1. 程式人生 > >Oracle下服務端字符集修改

Oracle下服務端字符集修改

oracle characterset

在Oracle下客戶端中設置的字符集應於服務端保持一致,否則會出現亂碼,而Oracle的客戶端無論是在Windows/DOS系統下還是Unix系統下都可以通過環境變量NLS_LANG來加以控制,至於操作也很簡單,在這裏就不做過多的說明,在這裏主要說一下如何在Oracle的服務端下如何正確的修改字符集。在修改的時候建議使用sysdba身份驗證,要註意的是新修改的字符集必須為舊字符集的超集,不然Oracle上修改字符集會報ORA-12712錯誤。而在平時可以查詢系統視圖得知當前Oracle數據庫中的字符集設置情況,如下:

SELECT * FROM v$nls_parameters WHERE PARAMETER IN ('NLS_LANGUAGE','NLS_TERRITORY','NLS_CHARACTERSET'); #通過NLS_LANGUAGE,NLS_TERRITORY,NLS_CHARACTERSET這三個變量查看
SELECT USERENV ('language') FROM DUAL;#或者通過USERENV函數也可以取得

操作方法也很簡單:

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount#進入維護模式
ORACLE instance started.

Total System Global Area 4275781632 bytes
Fixed Size                  2260088 bytes
Variable Size             905970568 bytes
Database Buffers         3355443200 bytes
Redo Buffers               12107776 bytes
Database mounted.
SQL> alter system enable restricted session;#在維護模式的基礎上再開啟restricted,防止其他用戶登錄連接

System altered.

SQL> alter system set job_queue_processes=0;#關閉系統的觸發器

System altered.

SQL> alter system set aq_tm_processes=0;#指定隊列監視進程個數,缺省是0,如果沒有改過可以不加

System altered.

SQL> alter database open;#打開數據庫

Database altered.

SQL> alter database character set internal_use al32utf8;#進行字符集修改

Database altered.

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup#最後重啟修改字符集生效
ORACLE instance started.

Total System Global Area 4275781632 bytes
Fixed Size                  2260088 bytes
Variable Size             905970568 bytes
Database Buffers         3355443200 bytes
Redo Buffers               12107776 bytes
Database mounted.
Database opened.


Oracle下服務端字符集修改