我的oracle行为与文档不匹配。
这是一个SQL示例,我必须描述我的问题:
with t as (
select 'name' as s from dual
union all
select 'name[' as s from dual
union all
select 'na[me' as s from dual
union all
select '[name' as s from dual
union all
select 'name]' as s from dual
union all
select 'na]me' as s from dual
union all
select ']name' as s from dual
union all
select 'name[]' as s from dual
union all
select 'na[]me' as s from dual
union all
select '[]name' as s from dual
union all
select '[name]' as s from dual
union all
select 'na[me]' as s from dual
union all
select '[na]me' as s from dual
)
select s from t where t.s like '%]%' escape '\'
我能找到的每一份文件都说了同样的话:你应该在你的like查询中转义方括号([])。
但出于某种原因,这就是我所拥有的:
SQL:select s from t where t.s like '%]%' escape '\'
输出:
name]
na]me
]name
name[]
na[]me
[]name
[name]
na[me]
[na]me
SQL:select s from t where t.s like '%\]%' escape '\'
输出:
ORA-01424: missing or illegal character following the escape character
01424. 00000 - "missing or illegal character following the escape character"
*Cause: The character following the escape character in LIKE pattern is
missing or not one of the escape character, '%', or '_'.
*Action: Remove the escape character or specify the missing character.
Error at Line: 28 Column: 32
在这两种情况下,“with”保持不变,我只是从我的“like”中添加\remove转义符。
我有点困惑,这不是我所期望的,根据文献。
我不是甲骨文Maven,所以我想我错过了一些东西。
我的版本是:
SELECT * FROM v$version;
Oracle Database 12c Standard Edition Release 12.2.0.1.0 - 64bit Production
PL/SQL Release 12.2.0.1.0 - Production
"CORE 12.2.0.1.0 Production"
TNS for Linux: Version 12.2.0.1.0 - Production
NLSRTL Version 12.2.0.1.0 - Production
1条答案
按热度按时间vs3odd8k1#
唯一可以转义的字符是具有特殊含义的字符:
_
和%
以及转义字符本身。其他都不需要转义。[
和]
并不特殊,不适用于普通的LIKE
。只需完全省略转义子句即可。