Oracle中文亂碼解決辦法總結

來源:互聯網
上載者:User

AMERICAN_AMERICA.WE8ISO8859P1,這個字元編碼是西歐字元編碼,對應於.Net的就是iso-8859-1字元編碼,所以只需要改到系統的預設字元編碼就行了.

解決方案:

(1) 伺服器端重新安裝ORACLE

  在重新安裝ORACLE 時選擇與原卸出資料一致的字元集(本例為US7ASCII)。

  載入原卸出的資料。

  這種情況僅僅使用於空庫和具有同一種字元集的資料。

(2)

寫一個函數:

 代碼如下 複製代碼

 /**//// <summary>
        /// 將西歐字元編碼轉換成GB2312
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
public static string Convert8859P1ToGB2312(string s)
{
   return System.Text.Encoding.Default.GetString(System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(s));
 }

(3)強行修改伺服器端ORACLE當前字元集

在用imp命令載入資料前,先在用戶端用sql*plus登入system DBA使用者,執行下列SQL語句進行當前ORACLE資料庫字元集修改:

 代碼如下 複製代碼

SQL > create database character set US7ASCII
  * create database character set US7ASCII
  ERROR at line 1:
  ORA-01031: insufficient privileges


(3)顯示中文亂碼

在Redhat上安裝Oracle 10g沒有設定字元集,採用的是作業系統預設字元集:WE8ISO8859P1,將字元集修改為:ZHS16GBK。由於過程無法復原,首先需要備份資料庫。
1.資料庫全備

 代碼如下 複製代碼

2.查詢當前字元集
SQL> select * from nls_database_parameters where parameter='NLS_CHARACTERSET';
PARAMETER VALUE
---------------------------------------- ----------------------------------------
NLS_CHARACTERSET WE8ISO8859P1

3.關閉資料庫
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

4.啟動資料庫到mount狀態

SQL> startup mount
ORACLE instance started.
Total System Global Area 205520896 bytes
Fixed Size 1266608 bytes
Variable Size 100666448 bytes
Database Buffers 100663296 bytes
Redo Buffers 2924544 bytes
Database mounted.

5.限制session

SQL> alter system enable restricted session;
System altered.

6.查詢相關參數並修改

SQL> show parameter job_queue_processes;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
job_queue_processes integer 10

SQL> show parameter aq_tm_processes;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
aq_tm_processes integer 0

SQL> alter system set job_queue_processes=0;
System altered.

7.開啟資料庫

SQL> alter database open;
Database altered.

8.修改字元集

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

出現錯誤提示,新字元集必須是老字元集的超集,也就原來字元集是新字元集的子集,可以再Oracle官方文檔上查詢字元集內含項目關聯性。下面使用Oracle內部命令internal_use,跳過超集檢查,生產環境不建議使用此方法。

SQL> alter database character set internal_use ZHS16GBK;
Database altered.

9.查詢當前字元集
SQL> select * from nls_database_parameters where parameter='NLS_CHARACTERSET';
PARAMETER VALUE
---------------------------------------- ----------------------------------------
NLS_CHARACTERSET ZHS16GBK

10.關閉資料庫

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

11.啟動資料庫到mount狀態

SQL> startup mount
ORACLE instance started.
Total System Global Area 205520896 bytes
Fixed Size 1266608 bytes
Variable Size 100666448 bytes
Database Buffers 100663296 bytes
Redo Buffers 2924544 bytes
Database mounted.

12.將相關參數改回原來值

SQL> alter system set job_queue_processes=10;
System altered.

13.開啟資料庫

SQL> alter database open;
Database altered.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.