我想获取名为'pl_name'的列,其中包含_5M_
。所以我确实执行了以下查询,但是它给出了所有值,但是我想要像pl_name
那样的AR_5M_testclient_986
使用的查询如下
select *from mn_table where status='Y' and upper(pl_name) like'%_5M_%'
答案 0 :(得分:-1)
_
在SQL中被视为通配符,因此它实际上试图匹配任何字符。您可以将_
包装在[]
中。这应该返回您想要的内容:
select * from mn_table where status='Y' and upper(pl_name) like'%[_]5M[_]%'
这将匹配方括号中的任何字符。
或者,使用ESCAPE '\'
进行转义:
select * from mn_table where status='Y' and upper(pl_name) like'%\_5M\_%' ESCAPE '\'
答案 1 :(得分:-1)
将下划线视为通配符条目。使用[_]
。
select * from mn_table where status='Y' and upper(pl_name) like '%[_]5M[_]%';