MYSQL建立FUNCTION--中文姓名個資掩碼
CREATE DEFINER=`%`@`%` FUNCTION `get_mask_name`(name varchar(50) CHARSET utf8mb4 ) RETURNS text CHARSET utf8mb4 DETERMINISTIC BEGIN DECLARE x varchar(50) CHARSET utf8mb4 DEFAULT ''; if isnull(name)=false then case char_length(TRIM(name)) when 1 then set x=TRIM(name); when 2 then set x=left(trim(name),1)+'O'; ELSE set x=CONCAT(left(trim(name),1) ,REPEAT('O',char_length(trim(name))-2) ,right(trim(name),1)); END case; end if; RETURN x; END