ORACLE 一个简单的存储过程逐行处理

来源:互联网 发布:遗传算法的步骤 编辑:程序博客网 时间:2024/05/19 08:25
create or replace package packttt is 
       type cur_ttt is ref cursor;
end packttt;
/






create or replace procedure procttt(p_id number,p_cur packttt.cur_ttt)
is
       v_sql varchar2(4000);
begin 
       if p_id = 0 then
          open p_cur for select * from ttt;
       else
          v_sql := 'select * from ttt where a=:p_id';
          open p_cur for v_sql using p_id;  
       end if;
end procttt;
/




declare
    v_id number :=0;
    v_row ttt%rowtype;
    p_cur packttt.cur_ttt;


begin 
    procttt(v_id,p_cur);
    loop
      fetch p_cur into v_row;
      exit when p_cur%notfound;
      dbms_output.put_line(v_row.c||'='||v_row.a);
    end loop;
    close p_cur;
end;
/