2个字符串:
1,2,3
3,4,5
判断是否有交集如上面交集3
CREATE DEFINER=`root`@`%` FUNCTION `find_same_group`(`source` varchar(255),`target` varchar(255)) RETURNS int(11)
READS SQL DATA
BEGIN
#Routine body goes here...
declare i int(11) DEFAULT 0;
declare x int(11) DEFAULT 0;
declare tmp VARCHAR(255) DEFAULT source;
declare now VARCHAR(255) DEFAULT '';
set i = length(source) - length(replace(source,',',''))+1;
out_label: BEGIN
while i>0 do
set now=SUBSTRING_INDEX(tmp,',',1);
set tmp=SUBSTRING_INDEX(tmp,',',-(i-1));
set i = i - 1;
if FIND_IN_SET(now,target)<>0 then
set x=1;
leave out_label;
END IF;
end while;
END out_label;
return x;
END