前言:

在取得Oracle證照後,工作上有關Oracle的問題就開始如雪片般飄來,無論這些問題是否
曾經學習過或處理過。相對的,因為對於這部分比新手稍微了解一些,在了解問題與處
理問題速度上,會較快速一些。

一樣是專案的需求,將目前現行運作的系統,其資料匯入目前開發的系統資料庫進行流程
測試。理所當然,系統驗收的項目也包含過去歷史資料。


舊有系統取得資料的方法,是藉由exp指令匯出dmp檔案。
我們取得dmp檔案,藉由imp指令匯入我們需要的資料表,再進行後續的處理。
這篇文章除了記錄如何使用imp/exp指令外,也說明了匯入字元集不同時的處理方法。
另外說明遭遇字符集問題,導致匯入資料變成亂碼的問題與簡易解決方法。

主要內容為:
1. imp指令
2. imp 亂碼問題 (nls_lang and charset)


執行步驟:

指令說明:
輸入imp -help可以看見指令參數說明。




1. imp 指令


example 1:  
step 1.開啟命令提示字元,並輸入下面指令
         open command line and enter command as below: 

imp system/password@claorcl tables=TableName file=D:\Hyweb\xxxx\S2mgr_20150305.dmp log=D:\Hyweb\xxxx\Log.txt





step 2.開啟oracle SQL Developer,並輸入下面指令
         open oracle SQL Developer and enter command as below: 

desc SYSTEM.TABLE_NAME




step 3.開啟oracle SQL Developer,並輸入下面指令
         open oracle SQL Developer and enter command as below: 

SELECT * FROM SYSTEM.TABLE_NAME




example 2:
step 1.開啟命令提示字元,並輸入下面指令
         open command line and enter command as below: 

imp system/password@claorcl tables=TableName file=D:\Hyweb\xxxx\S2mgr_20150424.dmp log=D:\Hyweb\xxxx\Log.txt




step 2.開啟oracle SQL Developer,並輸入下面指令
         open oracle SQL Developer and enter command as below: 

SELECT * FROM SYSTEM.TABLE_NAME




當大家觀看內容時,會發現內容變成亂碼,甚至有匯入欄位過長的問題產生。
這表示我們的設定與原環境設定有差異造成。
You will got result of query, but it probably is gibberish. There is something wrong with the text encoding.


2. imp 亂碼問題 (nls_lang setting)


當我們使用imp指令匯入,系統會提示匯出入端的字元集不同
When you execute commands of imp, system prompt to display messages about import/export charset setting



我可以在右鍵點選我的電腦,點選內容,點選進階系統設定,選擇環境變數、點選新增,輸入
變數名稱:NLS_LANG
變數值:AMERICAN_AMERICA.WE8ISO8859P1 (by your setting)
點選確定後,完成設定。

Step 1. Open System in Control Panel.
Step 2. On the Advanced tab, click Environment Variables, then click the name of the user
             variable you want to change.
Step 3.Click New button and add a new variable name and value, as follows.

variable name: NLS_LANG
variable value: AMERICAN_AMERICA.WE8ISO8859P1 (by your setting)

Step 4. Click OK to finish.




重新執行指令後,可以發現匯出入端字元集提示消失了,即可以解決亂碼問題。
When you execute commands of imp again, system does not prompt to display messages about import/export charset setting.





參考資料:

忘記了!


--
謝謝!