简体   繁体   English

与case和“=”的SQL区分大小写的字符串比较

[英]SQL case sensitive string comparison with like and “=”

i have one table named category. 我有一个名为category的表。

in this table i have two columns 1.) cat_id , 2.) cat_name 在这个表中我有两列1.) cat_id ,2。) cat_name

in this table i have added record with this value : cat_id = 1 , cat_name = test 在此表中,我添加了具有此值的记录: cat_id = 1cat_name = test

Now when i am going to run select query 现在,当我要运行选择查询时

SELECT * FROM category WHERE cat_name = 'Test'

this query returns me null result because in database record string is test and in query it's a Test mark the differance of capital string here. 此查询返回null结果,因为在数据库记录字符串中是test并且在查询中它是一个Test标记这里的大写字符串的差异。 Instade of null result i want the result with 1st record. null结果的Instade我想要第一条记录的结果。

also i want same result in vice versa small and capital string. 我也想要相同的结果,反之亦然小和大写字符串。

i am using sqlite as database. 我使用sqlite作为数据库。

使用上部功能。

SELECT * FROM category WHERE upper(cat_name) = upper('Test')
SELECT * FROM category WHERE cat_name = 'Test' COLLATE NOCASE;

use LOWER: 使用LOWER:

SELECT * FROM category WHERE LOWER(cat_name) = 'test'

will get you all combinations of TeSt 将为您提供TeSt的所有组合

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

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