如果我创建一个虚拟表,那么我知道我有一些匹配的数据:
create table t42 (field_acct_1 number, field_acct_2 number);
insert into t42 values (123, 456);
insert into t42 values (234, 567);
insert into t42 values (678, 123);
insert into t42 values (123, 123);
根据评论中提到的最新答案,我可以使用游标和批量收集(以允许重复值)来查找匹配项:
set serveroutput on
declare
type t_values is table of number;
l_values t_values;
cursor c1(cp_value number) is
select owner, table_name, column_name,
'select "' || column_name
|| '" from "' || owner ||'"."'|| table_name
|| '" where "' || column_name || '" = ' || cp_value
as query
from all_tab_columns
where column_name like '%ACC%'
and owner != 'SYS'
and data_type = 'NUMBER'
order by owner, table_name, column_name;
begin
for r1 in c1(123) loop
execute immediate r1.query bulk collect into l_values;
for i in 1..l_values.count loop
dbms_output.put_line(r1.owner
||'.'|| r1.table_name
||'.'|| r1.column_name
||':'|| l_values(i));
end loop;
end loop;
end;
/
我已将其限制为查找NUMBER
列以节省时间并排除SYS
表,但您可以添加过滤器以减少它必须做的更多工作。除此之外,这几乎是相同的想法。如果不清楚,请参阅较早答案中的嵌入式评论,以了解发生了什么。
这给了我(作为 owner.table.column:value):
SCOTT.T42.FIELD_ACCT_1:123
SCOTT.T42.FIELD_ACCT_1:123
SCOTT.T42.FIELD_ACCT_2:123
SCOTT.T42.FIELD_ACCT_2:123