使用 instr() 函数。
select 1
from dual
where instr('hello world!', 'world') > 0; -- 1
一般,我们判断逗号分隔的字符串时,会先进行一个预处理,用 ‘,’ 逗号把子字符串和目标字符串包裹起来。
这样就可以排除以下的误判:
select 1
from dual
where instr('ab,c,d,e', 'a') > 0; -- 1
正确写法:
select 1
from dual
where instr(',' || 'ab,c,d,e' || ',', ',' || 'a' || ',') > 0;