Reputation: 41
How do I do then following. There are no spaces or dashes in the card_number column
A column that displays the last four digits of the card_number column in this format: XXXX-XXXX-XXXX-1234. In other words, use Xs for the first 12 digits of the card number and actual numbers for the last four digits of the number.
Upvotes: 2
Views: 2872
Reputation: 872
With the help of substring and concat function you can do that
SELECT CONCAT('XXXX-XXXX-XXXX-', SUBSTRING(card_number, -4) AS masked_cc
FROM table;
Upvotes: 2
Reputation: 204904
select 'XXXX-XXXX-XXXX-' + substring(card_number, 16) as masked_card_number
from your_table
Upvotes: 2