Skip to content

Instantly share code, notes, and snippets.

@iorionda
Last active Nov 18, 2016
Embed
What would you like to do?
半角カナを全角カナに変換する
drop function if exists kana2KANA;
delimiter //
create function kana2KANA (data text) returns text deterministic
begin
declare kana1_len int(2);
declare kana2_len int(2);
declare kana1_h varchar(61) default 'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンッャュョァィゥェォー。「」、・';
declare kana1_z varchar(61) default 'アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンッャュョァィゥェォー。「」、・';
declare kana2_h varchar(52) default 'ガギグゲゴザジズゼゾダヂヅデドバビブベボパピプペポヴ';
declare kana2_z varchar(26) default 'ガギグゲゴザジズゼゾダヂヅデドバビブベボパピプペポヴ';
set kana1_len = char_length(kana1_z);
set kana2_len = char_length(kana2_z);
while kana2_len > 0 do
set data = replace(data, SUBSTRING(kana2_h,kana2_len*2-1,2), SUBSTRING(kana2_z,kana2_len,1));
set kana2_len = kana2_len - 1;
end while;
while kana1_len > 0 do
set data = replace(data, SUBSTRING(kana1_h,kana1_len,1), SUBSTRING(kana1_z,kana1_len,1));
set kana1_len = kana1_len - 1;
end while;
return data;
end;
//
delimiter ;
select kana2KANA("ガリレオガリレイ");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment