oracle - 如何在 oracle 数据库的所有字段/表中查找数据模式匹配项?
问题描述
具体来说,我正在尝试查找已输入到数据库中任何表的文本字段中的任何信用卡号。下面的代码适用于我知道主键是“ID”的单个表,但我找不到使这个动态的方法,以便我可以遍历数百个表和行。
drop table tab1 purge;
create table tab1(id number primary key, col1 varchar2(20), col2 varchar2(20), col3 varchar2(20));
Insert into TAB1 Values (1, 'No card here', 'Hello', 'nothing');
Insert into TAB1 Values (2, '1111222233334444', 'Visa', 'Hello');
Insert into TAB1 Values (3, 'Hello', 'MasterCard', '1111 2222 3333 4444');
Insert into TAB1 Values (4, 'Hello', '1111-2222-3333-4444', 'Visa');
Insert into TAB1 Values (5, 'Amex', 'Hello', '1111 222222 33333');
Insert into TAB1 Values (6, '111122222233333', 'Amex', 'Hello');
Insert into TAB1 Values (7, 'nothing', 'No card here', 'Hello');
COMMIT;
declare
myrow clob;
begin
for i in (select id from tab1) loop
select dbms_xmlgen.getxml('select * from tab1 where id=' || i.id) into myrow from dual;
if regexp_instr(myrow,'[0-9]{4}[ -]?[0-9]{4}[ -]?[0-9]{4}[ -]?[0-9]{4}|[0-9]{4}[ -]?[0-9]{6}[ -]?[0-9]{5}') > 0 then
dbms_output.put_line('May have found one: ' || to_char(i.id));
end if;
end loop;
end;
解决方案
推荐阅读
- php - php 文件不断出现双换行符
- c# - 如何使用 wpf 应用程序中的文件路径在发布请求上上传 .pdf 文件?
- azure-cosmosdb - Cosmos 读取区域的指标
- node.js - 如果异步函数用 try catch 包装,即使断言失败,mocha 测试也会通过
- reactjs - 如何使用 ReactJS 的 useMemo() 来冻结组件的内容?
- sql - 我怎样才能找到不同的这个 sql 2 行
- c++ - 如何将 > 运算符重载为布尔值?
- rabbitmq - 有没有办法让 RabbitMQ 在队列中保存更多数据?
- python-3.x - 如何在Python中输入()在一段时间内为空或无时执行
- content-management-system - 用于 Angular 项目的 BuilderIO 视觉 CMS 的替代品