如何在 SQL Server 中转义 _? [英] How do I escape _ in SQL Server?
本文介绍了如何在 SQL Server 中转义 _?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在 LIKE
语句中转义下划线字符.我尝试使用 ESCAPE
关键字如下:
I am trying to escape the underscore character in a LIKE
Statement. I have tried to use the ESCAPE
keyword as follows:
COLUMNNAME NOT LIKE '%[\_]xyz%' ESCAPE '\'
但它不起作用.当我真的希望它过滤掉 %_xyz%
时,它仍然过滤掉 %xyz%
.
but it doesn't work. It is still filtering out %xyz%
when I really want it to filter out %_xyz%
.
如果不是通过 ESCAPE
关键字,还能如何实现?
If not by the ESCAPE
keyword, how else can this be accomplished?
感谢任何帮助.
推荐答案
这应该可行:
COLUMNNAME NOT LIKE '%[_]xyz%'
这里不需要 ESCAPE.你写的也应该有效.
You don't need the ESCAPE here. What you wrote should also work.
如果你确实想使用 ESCAPE,你可以这样做:
If you do want to use ESCAPE you could do this:
columnname NOT LIKE '%\_xyz%' ESCAPE '\';
有关转义字符的文档位于此处.
Documentation on escape characters is here.
这篇关于如何在 SQL Server 中转义 _?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文