SQL- 搜索字符串时忽略大小写
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16082575/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQL- Ignore case while searching for a string
提问by shockwave
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
我在表
PriceOrderShipped
PriceOrderShippedInbound
PriceOrderShippedOutbound 中
有以下数据
在 SQL 中我需要编写一个查询来搜索表中的字符串。在搜索字符串时,它应该忽略大小写。对于下面提到的 SQL 查询
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%'
doesn't give.
不给。
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.
例如。当我搜索“PriceOrder”或“priceOrder”时,它会起作用,但“priceorder”或“Priceorder”不起作用。我已经尝试使用 COLLATE 进行以下查询,但它不起作用。让我知道我哪里出错了。
SELECT DISTINCT COL_NAME FROM myTable WHERE
COL_NAME COLLATE latin1_general_cs LIKE '%Priceorder%'
回答by Aditya Kakirde
Use something like this -
使用这样的东西 -
SELECT DISTINCT COL_NAME FROM myTable WHERE UPPER(COL_NAME) LIKE UPPER('%PriceOrder%')
or
或者
SELECT DISTINCT COL_NAME FROM myTable WHERE LOWER(COL_NAME) LIKE LOWER('%PriceOrder%')
回答by Miguel-F
See this similar question and answer to searching with case insensitivity - SQL server ignore case in a where expression
请参阅此类似的问题和答案以搜索不区分大小写 - SQL 服务器忽略 where 表达式中的大小写
Try using something like:
尝试使用类似的东西:
SELECT DISTINCT COL_NAME
FROM myTable
WHERE COL_NAME COLLATE SQL_Latin1_General_CP1_CI_AS LIKE '%priceorder%'
回答by Hangk
Like this.
像这样。
SELECT DISTINCT COL_NAME FROM myTable WHERE COL_NAME iLIKE '%Priceorder%'
In postgresql.
在 PostgreSQL 中。