create procedure pro
as
cursor t_sor is
select name,sourcetable,sourcefield from A;
str varchar2(100);
type tt is ref cursor;
vv tt;
v_sourcefield varchar2(50);
begin
for v_sor in t_sor loop
str:='select '||v_sor.sourcefield||' from '||v_sor.sourcetable;
open vv for str;
loop
 fetch vv into v_sourcefield;
 exit when vv%notfound;
 dbms_output.put_line(v_sor.name||v_sor.sourcetable||v_sor.sourcefield||v_sourcefield);
end loop;
close vv;
end loop;
end;
/

解决方案 »

  1.   

    感谢您的提示,为了返回表格形式的数据集,最后我还是写成函数形成
    create or replace function GetValue(fi_table in varchar2, fi_field in varchar2) return number
    is
      Result number;
      strSQL varchar2(100);
      
      TYPE tt is ref cursor;
      vv tt;BEGIN
      
      strSQL := 'select '||fi_field||' from '||fi_table;
      OPEN vv FOR strSQL;
       FETCH vv INTO Result;
      CLOSE vv;
      
      RETURN Result;   
      
      EXCEPTION
    WHEN NO_DATA_FOUND THEN
    RETURN  '';
      
    END;查询这样便可:
    select name,sourcetable,sourcefiled,getvalue(sourcetable,sourcefield) value from a谢谢