Skip to content

Instantly share code, notes, and snippets.

@tobias-khs
Created April 18, 2019 05:43
Show Gist options
  • Select an option

  • Save tobias-khs/72b2ba2893697c33ad17dd6403cef672 to your computer and use it in GitHub Desktop.

Select an option

Save tobias-khs/72b2ba2893697c33ad17dd6403cef672 to your computer and use it in GitHub Desktop.
Katakana Character to Gyo (行) MySQL function/procedure. Han-/Dakuten map to Normal/Base
CREATE DEFINER=`root`@`localhost` FUNCTION `mydb`.`gyoize`(str VARCHAR(255)) RETURNS varchar(2) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci
BEGIN
DECLARE gyo VARCHAR(2);
DECLARE kata VARCHAR(128);
DECLARE gyos VARCHAR(128);
DECLARE gyoPos INT;
SET kata = 'アイウエオヴカキクケコガギグゲゴサシスセソザジズゼゾタチツテトダヂヅデドナニヌネノハヒフヘホバビブベボパピプペポマミムメモヤユヨラリルレロワヲン';
SET gyos = 'アアアアアアカカカカカカカカカカササササササササササタタタタタタタタタタナナナナナハハハハハハハハハハハハハハハマママママヤヤヤラララララワワワ';
SET gyo = SUBSTRING(str, 1, 1);
SET gyoPos = POSITION(gyo IN kata);
RETURN SUBSTRING(gyos, gyoPos, 1);
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment