根据值反查数据库表及列

 

create   or   replace   procedure  visit_table(p_var  varchar as
p_table user_all_tables.table_name
% type;
cursor  p_data  is  ( select  t.table_name  from  user_all_tables t);

type p_col 
is  ref  cursor
p_c1 p_col; 

type p_a 
is  ref  cursor
p_aa p_a; 

p_name 
varchar2 ( 1000 );
p_type 
varchar2 ( 100 );
p_sql 
varchar2 ( 1000 );
p_result 
number ;
begin
    
open  p_data;
    loop
        
fetch  p_data  into  p_table;
        
exit   when  p_data % notfound;
        p_sql :
=   ' select * from  '   ||  p_table;
        
open  p_c1  for   ' select t.COLUMN_NAME,t.DATA_TYPE from user_tab_columns t where t.TABLE_NAME =:1 '
        using p_table;
        loop
            
fetch  p_c1  into  p_name,p_type;
            
exit   when  p_c1 % notfound;
            
if (p_type  <>   ' BLOB ' then
                      p_sql :
=   ' select count(*) a from  '   ||  p_table  ||   '  where to_char( ' || p_name  || ' )=:1 ' ;
                      
-- dbms_output.put_line(p_sql);
                       execute  immediate p_sql  into  p_result using p_var;
                      
if (p_result  > 0 then
                                  dbms_output.put_line(
' table:  ' ||  p_table  ||   '   columns:  '   ||  p_name);
                      
end   if ;
                      
-- returning into p_result;
             end   if ;
        
end  loop;
        
close  p_c1;
    
end  loop;
    
close  p_data;
end ;

dd 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值