Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- 자바기초스터디
- 이클립스
- Codewars
- 멀티쓰레드프로그래밍
- 오류
- java
- 시즌1
- 8kyu
- Oralce
- 주민번호마스킹
- Eclipse
- Linux
- 서울복층에어비앤비
- 파이썬
- https
- VMware
- CentOS
- 서울에어비앤비
- 이것이리눅스다
- 남산타워뷰
- JavaScript
- 6kyu
- 7kyu
- 사용자변경
- Python
- 중첩쿼리
- CentOS8
- monthPicker
- class파일바로보기
- SQL
Archives
- Today
- Total
보통사람
[SQL] 주민번호 마스킹 처리 본문
요즘은 주민번호와 같은 개인정보를 화면에 표시할 때 마스킹 처리하여 보여줘야 합니다.
오라클 REGEXP_REPLACE() 함수를 이용해서 처리하여 보았습니다.
-
OS : Windows 10 64bit
-
DataBase : Oracle 11g 64bit
SELECT REGEXP_REPLACE('1111112999999', '(\d{6})(\d{7})', '\1-\2') AS 주민번호
, REGEXP_REPLACE('1111112999999', '\d', '*','7') AS MASKING1
, REGEXP_REPLACE('1111112999999', '(\d{6})(\d{7})', '\1-*******') AS MASKING2
, REGEXP_REPLACE('1111112999999', '(\d{6})(\d{1})(\d{6})', '\1-\2' || '******') AS MASKING3
, REGEXP_REPLACE('1111112999999', '(\d{6})(\d{1})(\d{6})', '\1-\2******') AS MASKING4
FROM DUAL
;
모든 데이터가 자릿수에 맞게 있지 않을 수도 있기 때문에 이렇게 변경해보았습니다.
-- 마스킹처리
SELECT REGEXP_REPLACE('1', '(\d{6})(\d{1})(\d{0,7})', '\1-\2' || '******') AS LEN1 FROM DUAL
UNION ALL
SELECT REGEXP_REPLACE('11', '(\d{6})(\d{1})(\d{0,7})', '\1-\2' || '******') AS LEN2 FROM DUAL
UNION ALL
SELECT REGEXP_REPLACE('111', '(\d{6})(\d{1})(\d{0,7})', '\1-\2' || '******') AS LEN3 FROM DUAL
UNION ALL
SELECT REGEXP_REPLACE('1111', '(\d{6})(\d{1})(\d{0,7})', '\1-\2' || '******') AS LEN4 FROM DUAL
UNION ALL
SELECT REGEXP_REPLACE('11111', '(\d{6})(\d{1})(\d{0,7})', '\1-\2' || '******') AS LEN5 FROM DUAL
UNION ALL
SELECT REGEXP_REPLACE('111111', '(\d{6})(\d{1})(\d{0,7})', '\1-\2' || '******') AS LEN6 FROM DUAL
UNION ALL
SELECT REGEXP_REPLACE('1111112', '(\d{6})(\d{1})(\d{0,7})', '\1-\2' || '******') AS LEN7 FROM DUAL
UNION ALL
SELECT REGEXP_REPLACE('11111129', '(\d{6})(\d{1})(\d{0,7})', '\1-\2' || '******') AS LEN8 FROM DUAL
UNION ALL
SELECT REGEXP_REPLACE('111111299', '(\d{6})(\d{1})(\d{0,7})', '\1-\2' || '******') AS LEN9 FROM DUAL
UNION ALL
SELECT REGEXP_REPLACE('1111112999', '(\d{6})(\d{1})(\d{0,7})', '\1-\2' || '******') AS LEN10 FROM DUAL
UNION ALL
SELECT REGEXP_REPLACE('11111129999', '(\d{6})(\d{1})(\d{0,7})', '\1-\2' || '******') AS LEN11 FROM DUAL
UNION ALL
SELECT REGEXP_REPLACE('111111299999', '(\d{6})(\d{1})(\d{0,7})', '\1-\2' || '******') AS LEN12 FROM DUAL
UNION ALL
SELECT REGEXP_REPLACE('1111112999999', '(\d{6})(\d{1})(\d{0,7})', '\1-\2' || '******') AS LEN13 FROM DUAL
;
-- 일반
SELECT REGEXP_REPLACE('1', '(\d{6})(\d{1,7})', '\1-\2') AS LEN1 FROM DUAL
UNION ALL
SELECT REGEXP_REPLACE('11', '(\d{6})(\d{1,7})', '\1-\2') AS LEN2 FROM DUAL
UNION ALL
SELECT REGEXP_REPLACE('111', '(\d{6})(\d{1,7})', '\1-\2') AS LEN3 FROM DUAL
UNION ALL
SELECT REGEXP_REPLACE('1111', '(\d{6})(\d{1,7})', '\1-\2') AS LEN4 FROM DUAL
UNION ALL
SELECT REGEXP_REPLACE('11111', '(\d{6})(\d{1,7})', '\1-\2') AS LEN5 FROM DUAL
UNION ALL
SELECT REGEXP_REPLACE('111111', '(\d{6})(\d{1,7})', '\1-\2') AS LEN6 FROM DUAL
UNION ALL
SELECT REGEXP_REPLACE('1111112', '(\d{6})(\d{1,7})', '\1-\2') AS LEN7 FROM DUAL
UNION ALL
SELECT REGEXP_REPLACE('11111129', '(\d{6})(\d{1,7})', '\1-\2') AS LEN8 FROM DUAL
UNION ALL
SELECT REGEXP_REPLACE('111111299', '(\d{6})(\d{1,7})', '\1-\2') AS LEN9 FROM DUAL
UNION ALL
SELECT REGEXP_REPLACE('1111112999', '(\d{6})(\d{1,7})', '\1-\2') AS LEN10 FROM DUAL
UNION ALL
SELECT REGEXP_REPLACE('11111129999', '(\d{6})(\d{1,7})', '\1-\2') AS LEN11 FROM DUAL
UNION ALL
SELECT REGEXP_REPLACE('111111299999', '(\d{6})(\d{1,7})', '\1-\2') AS LEN12 FROM DUAL
UNION ALL
SELECT REGEXP_REPLACE('1111112999999', '(\d{6})(\d{1,7})', '\1-\2') AS LEN13 FROM DUAL
;
'정리' 카테고리의 다른 글
[JavaScript] 날짜 포맷 지정 (0) | 2019.10.11 |
---|---|
[SQL] MyBaits 문자열 비교 (0) | 2019.10.03 |
[Eclipse] 이클립스에 Log4j(1.x) 추가 (0) | 2019.08.11 |
[Eclipse] 이클립스에 JUnit 추가 (0) | 2019.08.10 |
[SQL] 1=1 구문, 1=0 구문을사용하는 이유 (0) | 2019.07.30 |