一、
In Microsoft SQL Server, if I want to search case insensitively in a case-sensitive database, I can run the following SQL:
SELECT*FROM MyTable
WHERE MyField ='BobDillon'COLLATE Latin1_General_CI_AI
And that will find all "bobdillon" entries.
If I want to do the same in Oracle, I know I can do this:
SELECT*FROM MyTable
WHERE UPPER(MyField)='BOBDILLON'
But I want to know if there is a direct equivalent to the collate keyword, so I can search for case sensitivity and accent sensitivity as I see fit.
a:SELECT*
FROM MyTable
WHERE NLSSORT(MyField,'NLS_SORT = Latin_CI')= NLSSORT('BobDillon','NLS_SORT = Latin_CI')
二、
Where can I query the current case-sensitivity setting of an oracle database?
I've tried looking in v$database, nls_database_parameters, and looking through the system packages, but none of them seem to provide the information I need...
In Oracle 10gR2:
SELECT*FROM NLS_SESSION_PARAMETERS
WHERE parameter IN('NLS_COMP','NLS_SORT')
SQL>ALTER SESSION SET NLS_COMP ='LINGUISTIC'2/
Session altered
SQL>SELECT COUNT(*) FROM dual WHERE'a'='A'
COUNT(*)
----------
1
SQL>ALTER SESSION SET NLS_COMP ='BINARY'
Session altered
SQL>SELECT COUNT(*) FROM dual WHERE'a'='A'
COUNT(*)
----------
0
From documentation:
NLS_COMPspecifies the collation behavior of the database session.Values:
BINARYNormally, comparisons in the
WHEREclause and inPL/SQLblocks is binary unless you specify theNLSSORTfunction.
LINGUISTICComparisons for all
SQLoperations in theWHEREclause and inPL/SQLblocks should use the linguistic sort specified in theNLS_SORTparameter. To improve the performance, you can also define a linguistic index on the column for which you want linguistic comparisons.
ANSIA setting of
ANSIis for backwards compatibility; in general, you should setNLS_COMPtoLINGUISTIC
http://stackoverflow.com/questions/1244804/where-can-i-query-an-oracle-databases-case-sensitivity
本文探讨了如何在Microsoft SQL Server和Oracle数据库中进行不区分大小写和字符集的搜索,介绍了使用不同方法实现案例敏感搜索,并提供了查询当前数据库案例敏感设置的方法。
896

被折叠的 条评论
为什么被折叠?



