SQL-在搜索字符串时忽略大小写 [英] SQL- Ignore case while searching for a string
问题描述
表中有以下数据
PriceOrderShipped
PriceOrderShippedInbound
PriceOrderShippedOutbound
在SQL中,我需要编写一个查询来搜索表中的字符串.在搜索字符串时,应忽略大小写.对于下面提到的SQL查询
I have the following data in a Table
PriceOrderShipped
PriceOrderShippedInbound
PriceOrderShippedOutbound
In SQL I need to write a query which searches for a string in a table. While searching for a string it should ignore case. For the below mentioned SQL query
SELECT DISTINCT COL_NAME FROM myTable WHERE COL_NAME LIKE '%PriceOrder%'
提供了以上所有数据,而
gives all the above data, whereas
SELECT DISTINCT COL_NAME FROM myTable WHERE COL_NAME LIKE '%Priceorder%'
不给.
例如.当我搜索"PriceOrder"或"priceOrder"时,它起作用,但"priceorder"或"Priceorder"不起作用. 我已尝试使用COLLATE使用以下查询,但无法正常工作.让我知道我哪里出错了.
Eg. when I search for 'PriceOrder' or 'priceOrder' it works but 'priceorder' or 'Priceorder' doesn't work. I have tried with the below query using COLLATE, but its not working. Do let me know where im going wrong.
SELECT DISTINCT COL_NAME FROM myTable WHERE
COL_NAME COLLATE latin1_general_cs LIKE '%Priceorder%'
推荐答案
使用类似这样的内容-
SELECT DISTINCT COL_NAME FROM myTable WHERE UPPER(COL_NAME) LIKE UPPER('%PriceOrder%')
或
SELECT DISTINCT COL_NAME FROM myTable WHERE LOWER(COL_NAME) LIKE LOWER('%PriceOrder%')
这篇关于SQL-在搜索字符串时忽略大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!