beckhambobo(beckham) ( ) 信誉:105  2003-02-17 17:12:00  得分:0 declare
type n_sor is ref cursor;
m_sor n_sor;
v_field1 t1.field1%type;
v_mc     t2.mc%type;
cursor t_sor is
select substr(feild2,1,instr(feild2,';')-1) table_name,substr(feild2,instr(feild2,';')+1,1) id from t1;
str varchar2(30);
begin
for v_sor in t_sor loop
v_table:=v_sor.feild2;
str:='select a.field1,b.mc from t1 a,'||v_sor.table_name||' b where a.'||v_sor.id||'='||v_sor.table_name||'.id';
open m_sor for str;
fetch m_sor into v_field1,v_mc;
loop
exit when m_sor%notfound;
dbms_output.put_line(v_field1,v_mc);
end loop;
close m_sor;
end loop;
/

解决方案 »

  1.   

    Oracle uses work areas to execute SQL statements and store processing information.
    A PL/SQL construct called a cursor lets you name a work area and access its stored
    information. There are two kinds of cursors: implicit and explicit. PL/SQL implicitly
    declares a cursor for all SQL data manipulation statements, including queries that
    return only one row. For queries that return more than one row, you can explicitly
    declare a cursor to process the rows individually. An example follows:
    DECLARE
    CURSOR c1 IS
    SELECT empno, ename, job FROM emp WHERE deptno = 20;  拷贝的,,看看
      

  2.   

    返回记录集用到游标变量相当简便,相当于动态执行sql.