0

Given table has debit card numbers. I want to write a code to mask the debit card numbers in which the middle 4 numbers are replaced with X. The table is as follows:

enter image description here

I want the following output:

enter image description here

I have written the following code but it is giving errors:

UPDATE
Debit_card_master
SET
Debit_card = LEFT(Debit_card, 4) + REPLICATE(‘x’, 4) + RIGHT(Debit_card, 4) ;

Also, can anyone help me with the correct MySQL code for the same?

1
  • Oracle uses || for string concatenation. Voting to close as a typo. Commented Feb 1, 2021 at 13:02

1 Answer 1

0

Your code looks kind of appropriate for MySQL (although not quite). In Oracle, you can use regexp_replace():

regexp_replace(debit_card, '^(....)(....)', '\1xxxx')

You can test this first. In the update:

UPDATE Debit_card_master
    SET debit_card = regexp_replace(debit_card, '^(....)(....)', '\1xxxx');

Note: This assumes that the number is always 12 characters. Or, more specifically, it replaces the characters in position 5-8.

Sign up to request clarification or add additional context in comments.

2 Comments

PDATE Debit_card_master SET debit_card = regexp_replace(debit_card, '^(....)(....)', '\1xxxx'); In the above command, what does this mean? '^(....)(....)' - Do I have to replace it with something?
That is the regular expression pattern. It divides the first eight characters into two groups. Then this is replaced by the first group and four 'x's.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.