Database ( DB )/Database

mysql 전화번호 masking

노루아부지 2019. 8. 7. 18:54
반응형

DELIMITER //
CREATE DEFINER=`mcouponbo`@`%` FUNCTION `getMaskPhone`(`v_code` varchar(50)) RETURNS varchar(50) CHARSET utf8
BEGIN
declare return_value varchar(50);

SET v_code = replace(v_code, '-', '');

SELECT
CASE WHEN CHAR_LENGTH(v_code) < 9 THEN v_code
ELSE
CASE SUBSTRING(v_code, 1, 2) WHEN '02' THEN
CONCAT('02', '-', REPEAT('*', CHAR_LENGTH(v_code) - 6), '-', SUBSTRING(v_code, CHAR_LENGTH(v_code) - 3, CHAR_LENGTH(v_code)))
ELSE
CONCAT(SUBSTRING(v_code, 1, 3), '-', REPEAT('*', CHAR_LENGTH(v_code) - 7), '-', SUBSTRING(v_code, CHAR_LENGTH(v_code) - 3, CHAR_LENGTH(v_code)))
END
END INTO return_value;

RETURN return_value;
END//
DELIMITER ;

 

728x90
반응형

'Database ( DB ) > Database' 카테고리의 다른 글

oracle offset limit ( 오라클 페이징 처리 )  (0) 2019.08.07
mysql name(이름) masking  (0) 2019.08.07
MariaDB backup  (0) 2019.08.05
mariaDB 1418 error  (0) 2019.08.05
mysql user 생성  (0) 2019.08.05
loading