简体   繁体   English

SQL和Case不敏感条件

[英]SQL and Case Insensitive Conditions

I have noticed in MySQL a where clause like WHERE x = 'Test' will match regardless of case ('TEST', 'test', etc.) 我在MySQL中注意到WHERE x = 'Test'的where子句无论大小写都匹配('TEST','test'等)

When using PDO, is it fair to assume that this is the case with most database servers? 使用PDO时,可以假设大多数数据库服务器都是这种情况吗? For example, If I were to use MSSQL or Oracle, would this be the same case? 例如,如果我使用MSSQL或Oracle,这是否是相同的情况?

It's not the server that it depends on, but the collation. 它不是它依赖的服务器,而是整理。 Most databases will default to a case insensitive collation, so you can assume that, but if you ever run into one that is case sensitive it is easy to change. 大多数数据库将默认为不区分大小写的排序规则,因此您可以假设,但如果遇到区分大小写的数据库,则很容易更改。

Oracle is case sensitive with data by default eg 默认情况下,Oracle对数据区分大小写,例如

select * from 'test';

does not equal 不等于

select * from 'TEST';

Been a while since I last used them but I seem to recall Informix beiung case sensitive and Sybase I think is dependant on the collation. 自从我上次使用它们以来已经有一段时间,但我似乎记得Informix beiung区分大小写,而Sybase我认为这取决于整理。

As noted by other respondandt SQL Server is dependant on the collation. 正如其他响应所述,SQL Server依赖于排序规则。

So I think the only real answer is it depends on the RDBMS 所以我认为唯一真正的答案是它取决于RDBMS

SQL Server is case insensitive by default. 默认情况下,SQL Server不区分大小写。 In SQL Server you can use Collation to use case sensitive comparisons, see here . 在SQL Server中,您可以使用排序规则来使用区分大小写的比较,请参见此处

Oracle is case sensitive by default. 默认情况下,Oracle区分大小写。 You can use the 'UPPER' statement to perform case insensitive searches, see here . 您可以使用“UPPER”语句执行不区分大小写的搜索,请参见此处

You're correct, sql in general is case insensitive for string matching and that goes for almost all servers. 你是对的,sql通常对字符串匹配不区分大小写,几乎适用于所有服务器。

Here's an article showing how to do a case sensivive match in different ways though if you need it! 这是一篇文章,展示了如果你需要它,如何以不同的方式进行案例敏感性匹配!

http://vyaskn.tripod.com/case_sensitive_search_in_sql_server.htm http://vyaskn.tripod.com/case_sensitive_search_in_sql_server.htm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM