1. 程式人生 > 其它 >Oracle檢視字符集編碼

Oracle檢視字符集編碼

1、檢視資料庫編碼、客戶端編碼

--資料庫編碼,查詢的資料來源props$,這個代表的是資料庫字符集。
select * from nls_database_parameters where parameter = 'NLS_CHARACTERSET';
--其來源於v$parameter,表示客戶端的字符集的設定,可能是引數檔案,環境變數或者是登錄檔會話字符集環境
select * from nls_instance_parameters where parameter='NLS_LANGUAGE';
--session引數
select * from nls_session_parameters;

2、查看錶資料的位元組儲存資訊

select
    --資料的二進位制編碼表示
    asciistr(col1) A,
    --位元組資料,10進製表示
    dump(col1) C10,
    --位元組資料,16進製表示
    dump(col1,1016) C16,
    --資料的uncode編碼表示
    compose(col1) uncode,
    --資料的16進製表示
    utl_raw.cast_to_raw(col1) cn,
    --資料的16進位制的字串格式
    utl_raw.cast_to_varchar2(utl_raw.cast_to_raw(col1)) cn2,
    col1
from
    schema1.table1
;

3、設定客戶端(sqlplus)編碼
docker登陸:

docker exec -it e48c9419b4d4 /bin/bash

登陸oracle安裝使用者:

su - oracle

設定伺服器編碼:

vi ~/.bash_profile
export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"
# export NLS_LANG="AMERICAN_AMERICA.AL32UTF8"

source ~/.bash_profile

echo $NLS_LANG
# 顯示AMERICAN_AMERICA.ZHS16GBK表示編碼修改成功

sqlplus / as sysdba

# 向表中插入中文資料測試