本人非常非常喜欢傻瓜教程。
并不是因为傻瓜教程看了就成为傻瓜。
而是很多东西的表现层是不同的,但内核与机制是类似的。
所以我们不需要去记忆那么多固定的东西,就像SQL标准,DB2,SQL SERVER,ORACLE都有各自的实现。
好了,开始今天的总结:
首先,建立一个存储过程并通过out方式返回一个游标。
create or replace procedure sp_test(cur_arg out sys_refcursor ) as begin open cur_arg for select serv_id, serv_name from itmis_pri_serv_tbl where year = 2013; end;
然后再建立另一个存储过程并调用上面的存储过程。
create or replace procedure sp_tes2 as cur_calling sys_refcursor; v_serv_id varchar2(30); v_serv_name varchar2(200); begin sp_test(cur_calling); --调用存储过程,这样这个游标就有值了 loop fetch cur_calling into v_serv_id,v_serv_name; exit when cur_calling%notfound; dbms_output.put_line(v_serv_id); dbms_output.put_line(v_serv_name); end loop; close cur_calling; end;
注意,这里只能使用FETCH INTO 语句来为变量赋值。不能使用FOR。