【问题标题】:How to use special character '_' in where clause of oracle如何在oracle的where子句中使用特殊字符'_'
【发布时间】:2019-03-18 18:05:02
【问题描述】:

我想让名为“pl_name”的列包含_5M_。所以我做了以下查询,但它给出了所有的值,但我想要pl_name,比如AR_5M_testclient_986

使用的查询如下

select *from mn_table where status='Y' and upper(pl_name) like'%_5M_%'

【问题讨论】:

标签: c# .net oracle


【解决方案1】:

将下划线视为通配符条目。使用[_]

select * from mn_table where status='Y' and upper(pl_name) like '%[_]5M[_]%';

【讨论】:

    【解决方案2】:

    下划线 _ 在 SQL 中被视为通配符,因此它实际上是在尝试匹配任何字符。

    在 Oracle 中,您可以使用转义字符来转义特殊字符:

    select * from mn_table where status='Y' and upper(pl_name) like'%\_5M\_%' ESCAPE '\'
    

    或者,来自Oracle LIKE docs

    您还可以通过重复搜索转义字符本身。 例如,如果@是转义字符,那么您可以使用@@ 搜索@。

    select * from mn_table where status='Y' and upper(pl_name) like'%__5M__%' ESCAPE '_'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 2021-08-16
      • 2012-03-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多