问题描述
给定的表有借记卡号码。我想写个代码把中间4个数字换成X的借记卡号进行屏蔽,表格如下:
我想要以下输出:
UPDATE
Debit_card_master
SET
Debit_card = LEFT(Debit_card,4) + REPLICATE(‘x’,4) + RIGHT(Debit_card,4) ;
解决方法
您的代码看起来有点适合 MySQL(虽然不完全)。在 Oracle 中,您可以使用 regexp_replace()
:
regexp_replace(debit_card,'^(....)(....)','\1xxxx')
你可以先测试一下。在 update
中:
UPDATE Debit_card_master
SET debit_card = regexp_replace(debit_card,'\1xxxx');
注意:这里假设数字总是 12 个字符。或者,更具体地说,它替换位置 5-8 中的字符。