Oracle伺服器資料庫中文亂碼之字元集修改

來源:互聯網
上載者:User

最近安裝個Oracle 10g資料庫,dbca建庫的時候沒選字元集或者選錯的情況,匯入資料後,中文全部是亂碼(搞笑的是,中文亂碼 居然全部是個“靠”字),查看網路幾篇文章,也做了相應修改(以前按方法修改可以解決的,今天特例!),解決辦法如下:

SQL> connect / as sysdba;              ---dba使用者串連資料庫

SQL> select name,value$ from props$ where name like '%NLS%';---語句查詢當前資料庫伺服器字元集

NAME
------------------------------------------------------------
VALUE$
--------------------------------------------------------------------------------
NLS_LANGUAGE
AMERICAN

NLS_TERRITORY
AMERICA

NLS_CURRENCY
$


NAME
------------------------------------------------------------
VALUE$
--------------------------------------------------------------------------------
NLS_ISO_CURRENCY
AMERICA

NLS_NUMERIC_CHARACTERS
.,

NLS_CHARACTERSET           ----找到查出來的結果中的該項參數
WE8ISO8859P1

 

下面是修改過程:

SQL> shutdown immediate;     ---停止資料庫
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup mount           ---啟動資料庫到mount狀態
ORACLE instance started.

Total System Global Area 235999352 bytes
Fixed Size 450680 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.

---下面是修改過程,按步驟修改
SQL> alter session set sql_trace=true;

Session 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> set linesize 120;
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;

# 使用INTERNAL_USE可以跳過超集的檢查,

(ALTER DATABASE character set INTERNAL_USE )

Database altered.
SQL> shutdown immediate;      ---再停止資料庫
Database closed.
Database dismounted.
ORACLE instance shut down.

---啟動資料庫
SQL> STARTUP
ORACLE instance started.

Total System Global Area 235999352 bytes
Fixed Size 450680 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.
Database opened.
SQL>

 

----再次查看當前字元集

SQL> select name,value$ from props$ where name like '%NLS%';

NAME
------------------------------
VALUE$
--------------------------------------------------------------------------------
NLS_LANGUAGE
SIMPLIFIED CHINESE

NLS_TERRITORY
CHINA

NLS_CURRENCY
?


NAME
------------------------------
VALUE$
--------------------------------------------------------------------------------
NLS_ISO_CURRENCY
CHINA

NLS_NUMERIC_CHARACTERS
.,

NLS_CHARACTERSET
ZHS16GBK  ---【已經修改成為中文編碼了】

今天的情況特殊,修改完了,中文亂碼還是“靠”字,- -

後來試著修改系統字元集

在oracle下 .bash_profile 檔案裡面加入

export NLS_LANG="Simplified Chinese_CHINA.ZHS16GBK"
再次登入查看,還是不行

最後把NLS_LANG中後面的字元集ZHS16GBK修改成AL32UTF8,查看結果,搞掂完成,回家!

總結:要系統字元集和資料庫字元集相對應才會解決中文亂碼問題,dbca建庫時,也要注意字元集選擇問題。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.