用游标实现吧: declare type t_sor is ref cursor; v_sor t_sor; str varchar2(50); v_monthr longyuan.BCS_MONTH_R%rowtype; begin str:='select * from longyuan.BCS_MONTH_R order by AgentDepartID'; open v_sor for str; loop fetch v_sor into v_monthr; exit when v_sor%notfound; dbms_output.put_line(v_monthr); end loop; end; /
declare
type t_sor is ref cursor;
v_sor t_sor;
str varchar2(50);
v_monthr longyuan.BCS_MONTH_R%rowtype;
begin
str:='select * from longyuan.BCS_MONTH_R order by AgentDepartID';
open v_sor for str;
loop
fetch v_sor into v_monthr;
exit when v_sor%notfound;
dbms_output.put_line(v_monthr);
end loop;
end;
/