oracle 存储过程返回数组的方法:
1.建立包
create or replace package test is
TYPE filename_array IS TABLE OF varchar2(1);
filename filename_array;
end test;
2. 建立存储过程
create or replace procedure test_array(v_cfjg out test.filename_array ) is
begin DECLARE i number;
D_cfjg dic_cfjg%rowTYPE;
-- D_nr dic_cfjg%rowTYPE;
cursor c1 is SELECT * FROM dic_cfjg;
BEGIN
i:=0;
v_cfjg := test.filename_array(); --数组初始化
open c1;
LOOP fetch c1 into D_cfjg;
EXIT WHEN c1%NOTFOUND ;
i:=i+1;
v_cfjg.EXTEND;
-- DBMS_OUTPUT.PUT_LINE(TO_CHAR(D_cfjg.dm));
v_cfjg(v_cfjg.count):=D_cfjg.dm;
DBMS_OUTPUT.PUT_LINE(v_cfjg(v_cfjg.count));
-- 测试
-- FETCH C1 INTO D_cfjg;
-- EXIT WHEN c1%NOTFOUND ;
END LOOP;
end;
EXCEPTION
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE('TOO_MANY_ROWS');
WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE(sqlerrm);
end test_array;