🔹 Masking a Mobile Number in Oracle
Masking a mobile number means partially hiding digits for privacy while displaying only a few visible characters. Below are different ways to achieve this in Oracle.
✅ 1️⃣ Mask Middle Digits (Show First & Last 2 Digits)
🟢 Output
🔹 This keeps the first two and last two digits visible and replaces the middle six with ******
.
✅ 2️⃣ Mask All Except Last 4 Digits
🟢 Output
🔹 Uses RPAD('*', ...)
to replace all but the last 4 digits.
✅ 3️⃣ Mask Using CASE
(Dynamic Length Handling)
🟢 Output
🔹 Useful if the number length is inconsistent.
✅ 4️⃣ General Function to Mask Any Mobile Number
If you frequently need to mask numbers, a function can help.
Usage:
🟢 Output
🔹 Summary
Method | SQL Code | Output Example |
---|---|---|
Mask Middle 6 Digits | REGEXP_REPLACE(mobile, '(\d{2})\d{6}(\d{2})', '\1******\2') | 98******10 |
Mask All Except Last 4 | `RPAD('', LENGTH(mobile) - 4, '') | |
Mask First 5 Digits | `CASE WHEN LENGTH(mobile) = 10 THEN 'XXXXX' | |
Custom Function | CREATE FUNCTION mask_mobile(p_mobile) | 98******10 |
🔹 Masking Aadhaar Number in Oracle
Aadhaar numbers are 12-digit unique identification numbers, and masking them is essential for privacy. Below are different ways to mask an Aadhaar number in Oracle.
✅ 1️⃣ Mask Middle Digits (Show First & Last 4 Digits)
🟢 Output
🔹 This keeps the first and last 4 digits visible while masking the middle 4 digits with ****
.
✅ 2️⃣ Mask All Except Last 4 Digits
🟢 Output
🔹 This replaces all but the last 4 digits with *
.
✅ 3️⃣ Mask All Except First & Last 2 Digits
🟢 Output
🔹 Useful when only minimal information needs to be shown.
✅ 4️⃣ Create a Function for Aadhaar Masking
If you frequently need to mask Aadhaar numbers, a function can help.
Usage:
🟢 Output
🔹 Summary
Method | SQL Code | Output Example |
---|---|---|
Mask Middle 4 Digits | REGEXP_REPLACE(aadhaar, '(\d{4})\d{4}(\d{4})', '\1 **** \2') | 1234 **** 9012 |
Mask All Except Last 4 | `RPAD('', LENGTH(aadhaar) - 4, '') | |
Mask All Except First & Last 2 | `SUBSTR(aadhaar, 1, 2) | |
Custom Function | CREATE FUNCTION mask_aadhaar(p_aadhaar) | 1234 **** 9012 |
Let me know if you need modifications! 🚀