
使用 mysql 正则表达式查询含有日文假名的字段
对于查询含有日文平假名和片假名的字段,常规的 regexp 匹配可能不理想。以下是如何使用自定义函数进行准确查询:
`
create definer=wq19bar@% function jp_char_inside(s text) returns int(11)
begindeclare h text; declare p integer; declare l integer; declare head text; declare utf_8 text; set h = hex(s); set p = 1; set l = length(h); while p zuojiankuohaophpcn= l do set head = substr(h, p, 1); if head zuojiankuohaophpcn '8' then set p = p + 2; else set utf_8 = substr(h, p, 6); if (utf_8 youjiankuohaophpcn= 'E38181' and utf_8 zuojiankuohaophpcn= 'E3829E') then return 1; end if; if (utf_8 youjiankuohaophpcn= 'E382A1' and utf_8 zuojiankuohaophpcn= 'E383BE') then return 1; end if; set p = p + 6; end if; end while;return 0;
end
`










