现有三个逗号拼接的字符串:A:'86,8611,8612,8613' B: '86,8612' C:‘8612,8614’
其中A完全包含B ,
A不完全包含C,
使用如下函数后
selecttestSplit(A,B) from dual; --结果为1 即:完全包含
selecttestSplit(A,C) from dual; --结果为0 即:不完全包含
当您需要处理两个类似此情况的字符串时,可以使用如下Oracle自定义函数:
create or replace function testSplit(v_a varchar2,v_b varchar2)
return number as counta number; countb number; countc number; Begin counta := 0; countb := 0; countc := 0; select count(1) into counta from (SELECT REGEXP_SUBSTR(v_a,'[^,]+',1,rownum) deptida FROM DUAL CONNECT BY ROWNUM <= LENGTH(v_a) - LENGTH(REPLACE(v_a,','')) + 1) aa,(SELECT REGEXP_SUBSTR(v_b,rownum) deptidb FROM DUAL CONNECT BY ROWNUM <= LENGTH(v_b) - LENGTH(REPLACE(v_b,'')) + 1) bb where aa.deptida = bb.deptidb; select count(1) into countb from (SELECT REGEXP_SUBSTR(v_b,'')) + 1) bb; if counta = countb then countc := 1; return countc; end if; return countc; end testSplit; 原文链接:https://www.f2er.com/oracle/212403.html