mysql 正則表達(dá)式模糊查詢?nèi)瘴募倜?/strong>
問題:如何使用 mysql 正則表達(dá)式查詢包含日文平假名和片假名的字段,但目前的正則表達(dá)式查詢結(jié)果不準(zhǔn)確?
答案:
原先的正則表達(dá)式存在一定的局限性,這里提供一個(gè)函數(shù)來解決這個(gè)問題:
create definer=`wq19bar`@`%` function `jp_char_inside`(s text) returns int(11) begin declare 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 <= l do set head = substr(h, p, 1); if head < '8' then set p = p + 2; else set utf_8 = substr(h, p, 6); if (utf_8 >= 'e38181' and utf_8 <= 'e3829e') then return 1; end if; if (utf_8 >= 'e382a1' and utf_8 <= 'e383be') then return 1; end if; set p = p + 6; end if; end while; return 0; end
使用方法:
SELECT * FROM table_name WHERE jp_char_inside(title) = 1;
? 版權(quán)聲明
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載。
THE END