暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Oracle 仅替换字符串中16位数字的出现次数

askTom 2013-07-17
207

问题描述

我有一个表,其中有一个文本列,其中包含字符和数字数据。一些数字数据是一个16位的信用卡号码。我想将16位信用卡号码替换为空值,或999999999999 ,或“<信用卡号码掩码>”。替换值由您自行决定。

现在我只需要一个选择语句,但最终我将编写一个惰性触发器,在将记录插入到表中之前去除信用卡号码。

供参考1 : Oracle技术支持建议在将记录插入sys.aud$表的SQLBID列中之前,使用on-ined触发器去除信用卡号。

供参考2 : *.audit_track='DB_EXTSED'的设置。我不想将此设置更改为不填充sys.aud$表中的SQLbind列的设置。

供参考3 :我不想替换任何长度不是16位的数字。

DDL :
拖放表测试数据;
创建表testdata (test1 varchar2(100)) ;

插入测试数据值('这是信用卡号码1234567890123456这是电话号码2538887777邮政编码98030这是另一个信用卡号码2345678901234567');
承诺;





专家解答

ops$tkyte%ORA11GR2> create table t ( x varchar2(200) );

Table created.

ops$tkyte%ORA11GR2>
ops$tkyte%ORA11GR2> insert into t values ( 'this is 16 1234567890123456 blah blah...' );

1 row created.

ops$tkyte%ORA11GR2> insert into t values ( 'this is a zip code 18017 16 1234567890123456 blah blah...' );

1 row created.

ops$tkyte%ORA11GR2> insert into t values ( 'this is a credit card number 1234567890123456 this is a phone number 2538887777 this is a zip code 98030 this is another credit card number 2345678901234567');

1 row created.

ops$tkyte%ORA11GR2> select regexp_replace( x, '([[:digit:]]{16})', 'xxxxxxxxxxxxxxxx' ) from t;

REGEXP_REPLACE(X,'([[:DIGIT:]]{16})','XXXXXXXXXXXXXXXX')
-------------------------------------------------------------------------------
this is 16 xxxxxxxxxxxxxxxx blah blah...
this is a zip code 18017 16 xxxxxxxxxxxxxxxx blah blah...
this is a credit card number xxxxxxxxxxxxxxxx this is a phone number 2538887777
 this is a zip code 98030 this is another credit card number xxxxxxxxxxxxxxxx



「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论