做一個2個資料庫間資料比較工具時遇到ORACLE中漢字排序的問題。
使用一下SQL
select *
from T_0303003
order by stock_holder
進行選取資料時(stock_holder為存放中文的欄位),結果發現兩庫返回的記錄順序不一致。琢磨之後應該為字元集問題,一個庫字元集為系統預設字元集,另一個庫為UTF-8字元集。尋找資料後發現,對於中文欄位的排序,應該使用以下方式:
-- 按拼音排序 (系統預設)
select *
from T_0303003
order by nlssort(stock_holder,'NLS_SORT=SCHINESE_PINYIN_M');
-- 按部首排序
select *
from T_0303003
order by nlssort(stock_holder,'NLS_SORT=SCHINESE_RADICAL_M');
-- 按筆畫排序
select *
from T_0303003
order by nlssort(stock_holder,'NLS_SORT=SCHINESE_STROKE_M');
ORACL官方論壇討論:
http://www.oracle-database.cn/oracle_database_It-english-database-0-251288.html
Have found a strange question recently, arrange in an order Chinese character order by in oracle, " crocodile's word has been ranked at the end to appear! Whether there is such a situation to know the greater part. Whether it is bug i
-----------------------------------------------------------
NLS _ SORT? ??
answer2:
r> -----------------------------------------------------------
1 perhaps this word is many sound words. 2 says and says according to what way you want to arrange in an order.
ans wer3:
-----------------------------------------------------------
arranges in an order according to the spelling, should need to set up NLS _ SORT. Have Still in test test finish tell and then you body.
answer4:
-----------------------------------------------------------
O In RACLE, arrange in an order question 1. //Arrange in an order 2 according to the stroke. select * from dept order by nlssort(name,NLS _ SORT =SCHINESE _ STROKE _ M); 3.//Press Take the radical and arrange in an order 4. select * from dept order by nlssort(name,NLS _ SORT =SCHINESE _ RADICAL _ M); 5.//Arrange in an order according to the spelling, this arranges in an order the side for systematic acquiescenc Formula 6. select * from dept order by nlssort(name,NLS _ SORT =SCHINESE _ PINYIN _ M); Can revise NLS _ SORT parameter