oracle小笔记
select CASE WHEN ASCIISTR(name) LIKE '%\%' AND LENGTH(name) = 2 THEN '*' || SUBSTR(name, -1) --脱敏姓名中文2个汉字 WHEN ASCIISTR(name) LIKE '%\%' AND LENGTH(name) > 2 THEN SUBSTR(name, 1, 1) || SUBSTR('***************************', 1, LENGTH(SUBSTR(name, 2, LENGTH(name) - 2))) || SUBSTR(name, -1) --脱敏姓名中文大于2个汉字 WHEN ASCIISTR(name) NOT LIKE '%\%' AND name NOT LIKE '% %' THEN SUBSTR(name, 1, 1) || SUBSTR('***************************', 1, LENGTH(SUBSTR(name, 2, LENGTH(name) - 2))) --脱敏姓名英文(J*********(JohnWilson)) WHEN ASCIISTR(name) NOT LIKE '%\%' AND REGEXP_COUNT(name, ' ') = 1 THEN SUBSTR(name, 1, 1) || SUBSTR('***************************', 1, LENGTH(SUBSTR(name, 2, INSTR(name, ' ') - 1))) || SUBSTR(name, LENGTH(SUBSTR(name, 2, INSTR(name, ' ')))) --脱敏姓名英文(M****** Jackson(Micheal Jackson)) WHEN ASCIISTR(name) NOT LIKE '%\%' AND REGEXP_COUNT(name, ' ') = 2 THEN SUBSTR(name, 1, 1) || SUBSTR('***************************', 1, LENGTH(SUBSTR(name, 2, INSTR(name, ' '))) - 1) || SUBSTR(name, LENGTH(SUBSTR(name, 2, INSTR(name, ' ') - 1)) + 1, 2) || SUBSTR('***************************', LENGTH(SUBSTR(name, 2, INSTR(name, ' ') + 2)), LENGTH(SUBSTR(name, 2, INSTR(name, ' ', 1, 2))) - LENGTH(SUBSTR(name, 2, INSTR(name, ' ') + 2))) || SUBSTR(name, LENGTH(SUBSTR(name, 2, INSTR(name, ' ', 1, 2)))) --脱敏姓名英文 G***** W***** Bush(George Walker Bush) ELSE SUBSTR(name, 1, 1) || '***********' END AS CUST_NAME from dual;
本文来自博客园,作者:diablo-427,转载请注明原文链接:https://www.cnblogs.com/diablo-427/p/17188093.html