Oracle: How to mask SSN and varying number queries

Example that works with SSN and I got it workingThe above is a query I have functioning. but how do I get the same effect when a column's data is varying in length and is unpredictable?

How would I get that same output in this scenario?
How can I make this query work to always get the last 4 digits so that every row reflects '*' followed by 4 digits? You'll notice that some only show 3 in the 'Don't Hardcode' column.
How can I fix the don't hardcode column to always show 4 numbers?Thanks
Mark_CoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PortletPaulfreelancerCommented:
is this the type of result you are looking for?
LAST_NAME    DON'T HARDCODE  SALARY
last_name    *20000          120000
last_name    *50000          150000
last_name    *5000           75000
last_name    *5000           65000
last_name    *5000           35000
last_name    **13000         1130000

Open in new window

try this perhaps :
SELECT
      last_name
     , substr(lpad(substr(salary,2,5),9,'*'),-length(salary)) "Don't Hardcode"
     , salary
     --, substr(salary,2,5)
FROM employee
;
/* ------- */

CREATE TABLE EMPLOYEE
	("SALARY" int)
;

INSERT ALL 
	INTO EMPLOYEE ("SALARY") 
		 VALUES (120000)
	INTO EMPLOYEE ("SALARY")
		 VALUES (150000)
	INTO EMPLOYEE ("SALARY")
		 VALUES (75000)
	INTO EMPLOYEE ("SALARY")
		 VALUES (65000)
	INTO EMPLOYEE ("SALARY")
		 VALUES (35000)
	INTO EMPLOYEE ("SALARY")
		 VALUES (1130000)
SELECT * FROM dual
;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mark_CoAuthor Commented:
Yeah i think something like that might work. Thanks
0
PortletPaulfreelancerCommented:
Great, thanks for the grading. Cheers, Paul
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.