我需要从DB表中返回一列信用卡号,"订单"列是"card_number"。它们在"订单"表上采用以下格式:
1234-5678-9012-3456
我需要 SELECT 语句返回以下内容:
我找到了没有连字符xxxx-xxxx-xxxx-3456
的示例,并在没有显示这一点的地方添加了连字符。我被难住了。
试试这个:
SELECT CONCAT('xxxx-xxxx-xxxx-', RIGHT(card_number,4)) FROM orders
RIGHT(card_number,4)
得到 card_number
的最后 4 个字符。它连接到字符串的末尾'xxxx-xxxx-xxxx-'
见右边和康卡特