80. Use like para desenfocar una matriz en el procedimiento almacenado
1. Use group_concat para convertir la matriz en una cadena
2. Use replace para reemplazar el conector
3. Use concat para conectar el script de empalme
需要模糊的数组
DECLARE ces_name VARCHAR(255) DEFAULT '';
select GROUP_CONCAT(name) into ces_name from (
select sdi.name from sys_dict sd
inner join sys_dict_item sdi
on sd.id = sdi.DICT_ID
where sd.code = 'jzf_qs_qlmc'
and sd.IS_DEL = '0'
and sdi.IS_DEL = '0'
)aa;
假如这个数组数据是:'apple,orange,xxx'
假如模糊比配的字段是name
REPLACE('apple,orange,xxx', ',', '%" OR name LIKE "%')
得到如下数据
apple%" OR name LIKE "%orange%" OR name LIKE "%xxx
缺少头和尾巴,需要再次填充
CONCAT('(name LIKE "%',REPLACE('apple,orange,xxx', ',', '%" OR name LIKE "%'), ',', '%" OR name LIKE "%'), '%")');
得到如下数据
(name LIKE "%apple%" OR name LIKE "%orange%" OR name LIKE "%xxx%")
已经成功得到想要的条件脚本