,

Credit Card Number (of different format) from specific column

Following query can be used to get the Credit Card Number (of different format) from specific column.

Column would have credit card Number in the text date. Date is not in any fixed format. And Credit Card Number would also not in any specific Format. In the following query, we have considered few credit card formats. In can include other formats accordingly as your requirement.

SELECT jtf_note_id, creation_date, LANGUAGE, notes,
CASE
WHEN INSTR (TRANSLATE (UPPER (notes), ‘0123456789’, ‘9999999999’),
‘99999999999999999’
) > 0
THEN SUBSTR (notes,
INSTR (TRANSLATE (UPPER (notes),
 ‘0123456789’,
 ‘9999999999’
 ),
 ‘99999999999999999’
 ),
LENGTH (‘99999999999999999’)
)
WHEN INSTR (TRANSLATE (UPPER (notes), ‘0123456789’, ‘9999999999’),
‘999999999999999’
) > 0
THEN SUBSTR (notes,
INSTR (TRANSLATE (UPPER (notes),
 ‘0123456789’,
 ‘9999999999’
 ),
 ‘999999999999999’
 ),
LENGTH (‘999999999999999’)
)
WHEN INSTR (TRANSLATE (UPPER (notes), ‘0123456789’, ‘9999999999’),
‘9999 9999 9999 9999’
) > 0
THEN SUBSTR (notes,
INSTR (TRANSLATE (UPPER (notes),
 ‘0123456789’,
 ‘9999999999’
 ),
 ‘9999 9999 9999 9999’
 ),
LENGTH (‘9999 9999 9999 9999’)
)
WHEN INSTR (TRANSLATE (UPPER (notes), ‘0123456789’, ‘9999999999’),
‘9999 999999 99999’
) > 0
THEN SUBSTR (notes,
INSTR (TRANSLATE (UPPER (notes),
 ‘0123456789’,
 ‘9999999999’
 ),
 ‘9999 999999 99999’
 ),
LENGTH (‘9999 999999 99999’)
)
WHEN INSTR (TRANSLATE (UPPER (notes), ‘0123456789’, ‘9999999999’),
‘9999-9999-9999-9999’
) > 0
THEN SUBSTR (notes,
INSTR (TRANSLATE (UPPER (notes),
 ‘0123456789’,
 ‘9999999999’
 ),
 ‘9999-9999-9999-9999’
 ),
LENGTH (‘9999-9999-9999-9999’)
)
WHEN INSTR (TRANSLATE (UPPER (notes), ‘0123456789’, ‘9999999999’),
‘9999-999999-99999’
) > 0
THEN SUBSTR (notes,
INSTR (TRANSLATE (UPPER (notes),
 ‘0123456789’,
 ‘9999999999’
 ),
 ‘9999-999999-99999’
 ),
LENGTH (‘9999-999999-99999’)
)
ELSE ‘No Credit card Number’
END “Credit card Number”
FROM jtf_notes_tl
WHERE 1 = 1
AND (TRANSLATE (UPPER (notes), ‘0123456789’, ‘9999999999’) LIKE (‘%999999999999999 %’) ) — 15 digit—
OR TRANSLATE (UPPER (notes), ‘0123456789’, ‘9999999999’) LIKE (‘%9999999999999999 %’)
OR TRANSLATE (UPPER (notes), ‘0123456789’, ‘9999999999’) LIKE (‘%9999 9999 9999 9999 %’)
OR TRANSLATE (UPPER (notes), ‘0123456789’, ‘9999999999’) LIKE (‘%9999 999999 99999 %’)
— below are different formats with ‘-‘ instead of ‘ ”
OR TRANSLATE (UPPER (notes), ‘0123456789’, ‘9999999999’) LIKE (‘%9999-9999-9999-9999 %’)
OR TRANSLATE (UPPER (notes), ‘0123456789’, ‘9999999999’) LIKE (‘%9999-999999-99999 %’)


I hope the above information would be helpful to you.
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply