<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Efficy Overflow Q&amp;A - Recent questions tagged multivalues</title>
<link>https://overflow.efficy.io/?qa=tag/multivalues</link>
<description>Powered by Question2Answer</description>
<item>
<title>Do 2 multivalues fields (such as OPPORTUNITIES.COMPETITORS) have at least one common value?</title>
<link>https://overflow.efficy.io/?qa=5283/multivalues-fields-opportunities-competitors-least-common</link>
<description>&lt;p&gt;I implemented an Oracle function :&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;create or replace FUNCTION CUSTOM_MULTIVALUES_MATCH(value_1 VARCHAR2, value_2 VARCHAR2)
RETURN NUMBER AS
value_exists NUMBER;
BEGIN
with value1(value1) as (
select regexp_substr(value_1,'[^;]+', 1, level) value1
from dual
connect by regexp_substr(value_1, '[^;]+', 1, level) is not null
)
,value2(value2) as (
select regexp_substr(value_2,'[^;]+', 1, level) value1
from dual
connect by regexp_substr(value_2, '[^;]+', 1, level) is not null
)
select (case when count(*) &amp;gt; 0 then 1 else 0 end) as &quot;Match&quot;
into value_exists
from value1 v1
inner join value2 v2 on v1.value1 = v2.value2;
return value_exists;
END;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Here is the result of the function for some test values :&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;CUSTOM_MULTIVALUES_MATCH(';1;2;',';1;') = 1
CUSTOM_MULTIVALUES_MATCH(';1;',';1;2;') = 1
CUSTOM_MULTIVALUES_MATCH(';1;2;',';3;4;') = 0
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Here is a query returning the opportunities having at least one competitor in common with a given opportunity:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;select o1.K_OPPORTUNITY, o1.NAME, o1.R_COMPETITORS
from 
R_OPPORTUNITIES o1, 
OPPORTUNITIES o2
where 
o1.K_OPPORTUNITY != o2.K_OPPORTUNITY
and o2.K_OPPORTUNITY = 2549
and CUSTOM_MULTIVALUES_MATCH(o1.COMPETITORS, o2.COMPETITORS) = 1;
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Database</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=5283/multivalues-fields-opportunities-competitors-least-common</guid>
<pubDate>Fri, 31 Jan 2020 14:05:10 +0000</pubDate>
</item>
</channel>
</rss>