【SQL】【脫敏】快速數據脫敏腳本


 mysql

-- 脫敏姓名
UPDATE table SET `name` = (if(LENGTH(name)>2,CONCAT(LEFT(name,1), '**' ),CONCAT(LEFT(name,1), '*' )));

-- 脫敏身份證號
UPDATE table SET idNumber = (if(LENGTH(idNumber)>6,CONCAT(LEFT(idNumber,4), '************' ,RIGHT(idNumber,2)),''));

-- 脫敏手機號
UPDATE table set phone = (if(LENGTH(phone)>3,CONCAT(LEFT(phone,3), '*****' ,RIGHT(phone,3)),''));

-- 脫敏郵箱
UPDATE table set email = (if(LENGTH(email)>3,CONCAT(LEFT(email,3), '**@**' ,RIGHT(email,3)),''));

-- 脫敏地址
UPDATE table set address = (if(LENGTH(address)>8,CONCAT(LEFT(address,5), '**********' ,RIGHT(address,3)),''));

-- 數量脫敏
UPDATE table set num = replace(replace(replace(replace(num,'4','6'),'2','7'),'3','8'),'1','5');

 

 

Sqlserver


-- 脫敏姓名
UPDATE table SET name = (iif(LEN(name)>2,CONCAT(LEFT(name,1), '**' ),CONCAT(LEFT(name,1), '*' )));

-- 脫敏身份證號
UPDATE table SET idNumber = (iif(LEN(idNumber)>6,CONCAT(LEFT(idNumber,4), '************' ,RIGHT(idNumber,2)),''));

-- 脫敏手機號
UPDATE table set phone = (iif(LEN(phone)>3,CONCAT(LEFT(phone,3), '*****' ,RIGHT(phone,3)),''));

-- 脫敏郵箱
UPDATE table set email = (iif(LEN(email)>3,CONCAT(LEFT(email,3), '**@**' ,RIGHT(email,3)),''));

-- 脫敏地址
UPDATE table set address = (iif(LEN(address)>8,CONCAT(LEFT(address,5), '**********' ,RIGHT(address,3)),''));

-- 數量脫敏
UPDATE table set num = replace(replace(replace(replace(num,'4','6'),'2','7'),'3','8'),'1','5');

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM