针对一个数据量不是很大的数据库的数据遍历。首先通过表user_tab_cols,查出需要该用户下所有字段的类型,
现在需要遍历某用户下出现“车坊”二字的表名列名,很明显可以去掉LONG,DATE等
字段,再者不考虑对大字段做操作。--select distinct data_type,data_length from user_tab_cols order by data_length desc;
declare
cursor c1 is select table_name,column_name
from user_tab_cols
where data_type not in ('LONG','FLOAT','DATE','BLOB');
C1_table_name VARCHAR2(30);
C1_column_name VARCHAR2(30);
type cur_type is ref cursor;
c2 cur_type;
c2_name varchar2(4000);--数据库中除了大字段以外,最长的字段类型长度为4000
begin
for i in c1 loop
C1_table_name:=i.table_name;
C1_column_name:=i.column_name;
open c2 for 'select '||C1_column_name||' from '||C1_table_name||' where '||C1_column_name||' like ''%车坊%''';
loop
fetch c2 into c2_name;
exit when c2 %notfound;
dbms_output.put_line(C1_table_name||'----------'||C1_column_name||'----------'||c2_name);
end loop;
close c2;
end loop;
end;
如果数据量比较大,建议后台执行该存储过程,将查出的值放到一个新的实体表中。