Regex |分隔符“%”类似“%”| |替换(替换(替换(分隔符| | | | | | | | |针| | | | | | | | | | | | | | | | | | | |。。。我这样做是为了确保打捆针和分离器都能安全逃脱。我还对转义字符进行了转义,以确保如果
Regex |分隔符“%”类似“%”| |替换(替换(替换(分隔符| | | | | | | | |针| | | | | | | | | | | | | | | | | | | |。。。我这样做是为了确保打捆针和分离器都能安全逃脱。我还对转义字符进行了转义,以确保如果,regex,oracle,plsql,Regex,Oracle,Plsql,|分隔符“%”类似“%”| |替换(替换(替换(分隔符| | | | | | | | |针| | | | | | | | | | | | | | | | | | | |。。。我这样做是为了确保打捆针和分离器都能安全逃脱。我还对转义字符进行了转义,以确保如果针头包含转义字符,它将不会被特殊处理。虽然这在某些情况下会起作用,但仍有可能针头包含特殊字符,因此您的答案不是一个完整的解决方案。不过还是要谢谢你:)虽然这在某些情况下是可行的,但仍有可能针会包含特殊字符,因此你的答案不是一个完整的解决方案。不
|分隔符“%”类似“%”| |替换(替换(替换(分隔符| | | | | | | | |针| | | | | | | | | | | | | | | | | | | |。。。我这样做是为了确保打捆针和分离器都能安全逃脱。我还对转义字符进行了转义,以确保如果针头包含转义字符,它将不会被特殊处理。虽然这在某些情况下会起作用,但仍有可能针头包含特殊字符,因此您的答案不是一个完整的解决方案。不过还是要谢谢你:)虽然这在某些情况下是可行的,但仍有可能针会包含特殊字符,因此你的答案不是一个完整的解决方案。不过还是要谢谢你:)
CREATE OR REPLACE
FUNCTION list_contains(needle_ IN VARCHAR2,
haystack_ IN VARCHAR2,
separator_ IN VARCHAR2 DEFAULT ',')
RETURN INTEGER
IS
BEGIN
IF regexp_like(haystack_, '(^|' || separator_ || ')' || needle_ || '(' || separator_ || '|$)') THEN
RETURN 1;
ELSE
RETURN 0;
END IF;
END list_contains;
list_conains('eve','john,eve,maria,steve') => 1
IF separator_ || haystack_ || separator_ LIKE '%'||separator_||needle_||separator_||'%' THEN
RETURN 1;
ELSE
RETURN 0;
END IF;
IF separator_ = '%' OR separator_ = '_'
THEN
separator_ := '\' || separator_;
END IF;
IF separator_ || haystack_ || separator_ LIKE
'%' || separator_ || needle_ || separator_ || '%' ESCAPE '\'
THEN
RETURN 1;
ELSE
RETURN 0;
END IF;
IF regexp_like(haystack_, '(^|\' || separator_ || ')' || needle_ || '(\' || separator_ || '|$)') THEN
CREATE OR REPLACE
FUNCTION list_contains(needle_ IN VARCHAR2,
haystack_ IN VARCHAR2,
separator_ IN VARCHAR2 DEFAULT ',')
return number AS
l_return_count number := 0;
BEGIN
with haystack_ary as (
select extractvalue(x.column_value, 'e') as val
from xmltable ('e' passing xmlparse( content '<e>' || replace(haystack_, separator_, '</e><e>') || '</e>')) x
)
select
--count(1)
--return as a "bool"(1=true,0=false)
decode(count(1), 0, 0, 1)
into l_return_count
from haystack_ary
where lower(needle_) = lower(haystack_ary.val);
return l_return_count;
END;
SELECT REGEXP_REPLACE('some.string[with(special)reg-exp]characters', '([][)(}{.$*+?,|^\])', '\\\1') "REGEXP_REPLACE" FROM dual;
select haystack_, needle_, separator_, instr(separator_||haystack_||separator_, separator_||needle_||separator_) result_, expected_
from (
select 'john,eve,maria,steve' as haystack_ , 'eve' as needle_, ',' as separator_, '>0'as expected_ from dual union all
select 'john,eve,maria,steve' as haystack_ , 'john' as needle_, ',' as separator_, '>0'as expected_ from dual union all
select 'john,eve,maria,steve' as haystack_ , 'joh' as needle_, ',' as separator_, '=0'as expected_ from dual union all
select 'john,eve,maria,steve' as haystack_ , 'steve' as needle_, ',' as separator_, '>0'as expected_ from dual union all
select 'john,eve,maria,steve' as haystack_ , 'stev' as needle_, ',' as separator_, '=0'as expected_ from dual union all
select 'john,eve,maria,steve' as haystack_ , 'teve' as needle_, ',' as separator_, '=0'as expected_ from dual union all
select 'john.maria.steve' as haystack_ , 'eve' as needle_, '.' as separator_, '=0'as expected_ from dual union all
select 'john_maria_steve' as haystack_ , 'eve' as needle_, '_' as separator_, '=0'as expected_ from dual union all
select 'john%maria%steve' as haystack_ , 'eve' as needle_, '%' as separator_, '=0'as expected_ from dual
) t;
HAYSTACK_ NEEDLE_ SEPARATOR_ RESULT_ EXPECTED_
john,eve,maria,steve eve , 6 >0
john,eve,maria,steve john , 1 >0
john,eve,maria,steve joh , 0 =0
john,eve,maria,steve steve , 16 >0
john,eve,maria,steve stev , 0 =0
john,eve,maria,steve teve , 0 =0
john.maria.steve eve . 0 =0
john_maria_steve eve _ 0 =0
john%maria%steve eve % 0 =0