【发布时间】:2016-05-04 00:28:26
【问题描述】:
我有一个类型为 CLOB 的列,包含逗号分隔值,例如“1,2,13,14”,我需要检查另一列(字符串)中的值是否可以与克洛布。我该怎么做?
例如。查找 3 是否在 '1,2,13,14' 中
我尝试了 InStr 和 regexp_instr,当尝试查看 3 是否在 '1,2,13,14' 中时,它们都会找到匹配项
请帮忙!!
【问题讨论】:
我有一个类型为 CLOB 的列,包含逗号分隔值,例如“1,2,13,14”,我需要检查另一列(字符串)中的值是否可以与克洛布。我该怎么做?
例如。查找 3 是否在 '1,2,13,14' 中
我尝试了 InStr 和 regexp_instr,当尝试查看 3 是否在 '1,2,13,14' 中时,它们都会找到匹配项
请帮忙!!
【问题讨论】:
您可以在要检查的字符串的开头和结尾添加一个逗号,然后将其与,3, 进行比较,如下所示:
with sample_data as (select '1,2,13,14' str from dual union all
select '11,22,3' str from dual union all
select '3,44,5' str from dual union all
select '19,3,394,49' str from dual union all
select '33,20' str from dual union all
select '3' str from dual union all
select '33,303' str from dual)
select str,
instr(','||str||',', ',3,') instr_3,
case when ','||str||',' like '%,3,%' then 'Y'
else 'N'
end is_3_present
from sample_data;
STR INSTR_3 IS_3_PRESENT
----------- ---------- ------------
1,2,13,14 0 N
11,22,3 7 Y
3,44,5 1 Y
19,3,394,49 4 Y
33,20 0 N
3 1 Y
33,303 0 N
我给了你几种不同的检查方法。
【讨论】: