oracel存儲過程要返回查詢結果,如何標記。
oracel存儲過程要返回查詢結果,如何標記。
------解决方案--------------------如果是返回一个值就out
如果是返回记录集就用数组
------解决方案--------------------由out参数来传出数值
------解决方案--------------------SQL> set serveroutput on
SQL> create or replace procedure p_fetch_5_row
2 (
3 v_owner varchar2
4 ,ret_cur out sys_refcursor
5 )
6 is
7 begin
8 open ret_cur for
9 select object_name
10 from dba_objects
11 where owner = v_owner
12 and rownum <= 5;
13 end p_fetch_5_row;
14 /
过程已创建。
SQL> create or replace procedure p_exec
2 is
3 v_cur sys_refcursor;
4 v_object_name varchar2(2000);
5 begin
6 p_fetch_5_row('SYS', v_cur);
7 loop
8 fetch v_cur into v_object_name;
9 exit when v_cur%notfound;
10 dbms_output.put_line(v_object_name);
11 end loop;
12
13 close v_cur;
14 end p_exec;
15 /
过程已创建。
SQL> exec p_exec
/1005bd30_LnkdConstant
/10076b23_OraCustomDatumClosur
/10297c91_SAXAttrList
/103a2e73_DefaultEditorKitEndP
/1048734f_DefaultFolder
PL/SQL 过程已成功完成。
------解决方案--------------------仔细看:
SQL> create or replace procedure p_exec
2 is
3 v_cur sys_refcursor;
4 v_object_name varchar2(2000);
5 begin
6 p_fetch_5_row('SYS', v_cur);
7 loop
8 fetch v_cur into v_object_name;
9 exit when v_cur%notfound;
10 dbms_output.put_line(v_object_name);
11 end loop;
12
13 close v_cur;
14 end p_exec;
15 /