Total Pageviews

2020/02/09

[Docker] 如何解決 Oracle Docker 匯入資料繁體中文亂碼問題

Problem
我有準備好 create table 與 insert data 的語法在指定目錄,並用以下指令啟動 docker:
docker run -d --shm-size=1g -p 8080:8080 -p 1521:1521 \
-v /Users/guojunyou/Documents/docker/local-initdb:/etc/entrypoint-initdb.d \
42dda6eba3ea

並成功啟動 Oracle docker
guojunyoude-iMac:~ guojunyou$ docker logs 4445b2acf933 --details
 Starting Oracle Net Listener.
 Starting Oracle Database 11g Express Edition instance.

 Database init...

 /start.sh: running /etc/entrypoint-initdb.d/data.sql

 Table created.

 1 row created.

 1 row created.

 1 row created.

 1 row created.

 End init.
 Oracle started successfully!

發現所 insert 的資料都是亂碼


How-To
這是因為編碼所導致的問題,在啟動指令增加一個參數
-e NLS_LANG="TRADITIONAL CHINESE_TAIWAN.AL32UTF8" 即可解決亂碼問題
docker run -d --shm-size=1g -p 8080:8080 -p 1521:1521 \
-e NLS_LANG="TRADITIONAL CHINESE_TAIWAN.AL32UTF8" \
-v /Users/guojunyou/Documents/docker/local-initdb:/etc/entrypoint-initdb.d \
42dda6eba3ea




No comments: