oracle雖然在.bash_profile中設定了NLS_LANG="SIMPLIFIED CHINESE_CHINA".ZHS16GBK;export NLS_LANG,但是在查詢帶有中文字元的表時,仍然亂碼的問題。
在生産環境中:
- 全備份資料庫。
-
檢視目前字元集:
select * from nls_database_parameters where parameter='NLS_CHARACTERSET';
查詢到結果是RedHat作業系統自己預設的字元集:WE8ISO8859P1
-
關閉資料庫
shutdown immediate;
-
啟動資料庫到挂載階段;mount
startup mount;
-
限制連接配接會話
alter system enable restricted session;
-
檢視工作程序隊列;
show parameter job_queue_processes;
show parameter aq_tm_processes;
-
更改工作隊列數為0個;
alter system set job_queue_processes=0;
-
打開資料庫;
alter system set character=ZHS16GBK;
執行完上個指令,如果報ORA-12712,這個錯誤,則表示要更改的新字元集必須是老字元集的超集;
于是更改語句,執行下面的語句;
alter database character set internal_use ZHS15GBK;
- 查詢目前資料庫的字元集是否更改成功。
- 成功後,關閉資料庫;
- 打開資料庫到mount階段;
-
更改工作隊列程序資料,為第六步查詢的結果;
alter system set job_queue_processes=10;
- 徹底打開資料