如何在 Oracle SQL Developer 中转义下划线?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42946040/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:24:22  来源:igfitidea点击:

How to escape underscores in Oracle SQL Developer?

sqloracle

提问by RedSea

If I want to select strings with underscores using Oracle SQL Developer, how do I have to escape those?

如果我想使用 Oracle SQL Developer 选择带下划线的字符串,我该如何转义这些字符串?

I tried:

我试过:

name like '%_%' 
name like '%'_%' 
name like '%\_%' 

but none of this helped.

但这些都没有帮助。

回答by Aleksej

You need to use the explicit escape; in this way you can decide a character to use for escaping and then use it in your LIKE.

您需要使用显式escape; 通过这种方式,您可以决定用于转义的字符,然后在您的LIKE.

For example, here I use the '!'to escape special characters:

例如,这里我使用'!'来转义特殊字符:

select str
from (
        select 'a_b' str from dual union all
        select 'ab'      from dual
     )
where str like '%!_%' escape '!' 

gives

STR
---
a_b

回答by skourkos

Oracle suggeststhe code below which workded for me:

Oracle建议使用以下对我有用的代码:

SELECT last_name 
    FROM employees
    WHERE last_name LIKE '%A\_B%' ESCAPE '\'
    ORDER BY last_name;