您可以为每个UserId
中的第一个生成GUID ,然后使用分析函数为具有相同UserId
的所有其他行使用相同的值:
SELECT MAX(maskedid) OVER (PARTITION BY userid) AS maskedid,
value
FROM (
SELECT CASE ROW_NUMBER() OVER (PARTITION BY userid ORDER BY ROWNUM)
WHEN 1
THEN SYS_GUID()
END AS maskedid,
userid,
value
FROM table_name
);
其中,对于示例数据:
CREATE TABLE table_name (UserID, Value) AS
SELECT 1, 23 FROM DUAL UNION ALL
SELECT 2, 10 FROM DUAL UNION ALL
SELECT 1, 45 FROM DUAL;
可输出:
MASKEDID |
VALUE |
0x0BFDC951F97909BCE06502163E386F05 |
23 |
0x0BFDC951F97909BCE06502163E386F05 |
45 |
0x0BFDC951F97A09BCE06502163E386F05 |
10 |
您可以使用任何函数而不是SYS_GUID ()
,例如DBMS_RANDOM.VALUE
:
SELECT MAX(maskedid) OVER (PARTITION BY userid) AS maskedid,
value
FROM (
SELECT CASE ROW_NUMBER() OVER (PARTITION BY userid ORDER BY ROWNUM)
WHEN 1
THEN DBMS_RANDOM.VALUE(0, 1e6)
END AS maskedid,
userid,
value
FROM table_name
);
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 23 HOURS 58 MINUTES 31 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
MASKEDID |
VALUE |
84046.38920350070167103410156941056149 |
23 |
84046.38920350070167103410156941056149 |
45 |
297835.63547525613908362909300172303338 |
10 |
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 23 HOURS 58 MINUTES 29 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE