NLS_SORT和NLS_COMP是Oracle兩個(gè)初始化參數(shù)。顧名思義睬捶,NLS_SORT和NLS_COMP是設(shè)置排序和比較的方式黔宛。通過設(shè)置這兩個(gè)參數(shù)可以實(shí)現(xiàn)自定義的排序和比較的方式。設(shè)置這兩個(gè)參數(shù)的值可以在數(shù)據(jù)庫創(chuàng)建的時(shí)候指定擒贸,也可以通過Alter Session語句來修改臀晃。如果是在創(chuàng)建數(shù)據(jù)庫的時(shí)候設(shè)定,那么是不能再修改的介劫,并在所有的Session中起作用徽惋。但是我們也通過Alter Session命令臨時(shí)改變這兩個(gè)參數(shù)的值,在會(huì)話中臨時(shí)使用一種特定的排序和比較的方式蜕猫。要改變所有的會(huì)話的排序和比較的方式寂曹,我們也可以通過修改注冊(cè)表的方式來達(dá)到目的,如果系統(tǒng)采用的多層體系架構(gòu)回右,并且所有的邏輯層代碼都部署在相同的應(yīng)用程序服務(wù)器(如IIS)上的隆圆。
查看會(huì)話中這兩個(gè)參數(shù)值,我們可以使用如下的查詢語句:
select * from NLS_SESSION_PARAMETERS;
官方的文檔說明:
NLS_SORT specifies the collating sequence for ORDER BY queries.
?If the value is BINARY, then the collating sequence for ORDER BY queries is based on the numeric value of characters (a binary sort that requires less system overhead).
?If the value is a named linguistic sort, sorting is based on the order of the defined linguistic sort. Most (but not all) languages supported by the NLS_LANGUAGE parameter also support a linguistic sort with the same name.
Note:
Setting NLS_SORT to anything other than BINARY causes a sort to use a full table scan, regardless of the path chosen by the optimizer. BINARY is the exception because indexes are built according to a binary order of keys. Thus the optimizer can use an index to satisfy the ORDER BY clause when NLS_SORT is set to BINARY. If NLS_SORT is set to any linguistic sort, the optimizer must include a full table scan and a full sort in the execution plan.
You must use the NLS_SORT operator with comparison operations if you want the linguistic sort behavior.
如果NLS_SORT不是設(shè)置為"Binary"翔烁,那么就會(huì)引起全表掃描渺氧,是不會(huì)使用索引的