1. 程式人生 > >Sybase BCP匯入資料時碰到中文編碼問題的解決方法

Sybase BCP匯入資料時碰到中文編碼問題的解決方法

在用 BCP 命令匯入其它機器匯出的檔案很容易碰到這樣的問題:

Server Message: cdr - Msg 2401, Level 11, State 2:
Character set conversion is not available between client character set 'iso_1' and server character set 'eucgb'.
 
Server Message: cdr - Msg 2411, Level 10, State 1:
No conversions will be done.
 
 
Starting copy...
CSLIB Message:  - L0/O0/S0/N24/1/0:
cs_convert: cslib user api layer: common library error: The conversion/operation was stopped due to a syntax error in the source field.
CSLIB Message:  - L0/O0/S0/N24/1/0:
cs_convert: cslib user api layer: common library error: The conversion/operation was stopped due to a syntax error in the source field.

這是由中文編碼引起的。解決方法是在BCP命令後面跟上如下引數:

-Jeucgb 設定客戶端編碼方式,解決前面的字元編碼告警。通常情況下客戶端編碼方式和伺服器都不一樣,即使在伺服器上執行也是如此。

-zchinese 設定資料庫語言,解決匯入中文錯誤。此選項的值在 資料庫安裝目錄/locales/下面能找到,各個資料夾就是可用的值。

另:通常使用 -c -t'|' 這樣的引數來指定使用文字方式匯入、管道符(|)為欄位值分隔符。