第一次使用sql语句查询带有_符号的内容时:
select a.* from attribute a where a.name = 'server.other.hostName' and a.value like '%_%'
发现查询的结果是全部的结果,与预期的结果不同,后来发现like语句中_符号是代表任意字符的意思,可使用scape关键字进行查询:
select a.* from attribute a where a.name = 'server.other.hostName' and a.value like '%|_%' escape '|'
这次得到的结果就是正确的
本文详细解释了在SQL查询中使用LIKE语句时,_符号代表任意字符的含义,并通过实例展示了如何正确使用scape关键字来精确匹配包含特定模式的数据。
1814

被折叠的 条评论
为什么被折叠?



