所以我要通过一个oracle数据库课程,我有一个功课,我必须创建一个过程并“返回”(我想返回)结果集而不使用refcursor,但我找到的所有示例都使用它。
让我说我有这个:
CREATE OR REPLACE PROCEDURE get_all_inventory() AS
BEGIN
SELECT * FROM Inventory;
END;
/
如何在不使用refcursor的情况下使过程返回结果集? 这有可能吗?
感谢。
编辑:如果有人知道在json中返回结果集的方法真的很棒!
答案 0 :(得分:1)
除了使用JSON之外,您还可以使用集合作为返回值。您必须先为您的程序创建一个包。这是一个示例代码:
create OR REPLACE package get_all_inventory_package is
type arrayofrec is table of Inventory%rowtype index by pls_integer;
procedure get_all_inventory (o_return_variable OUT arrayofrec);
end;
/
create OR REPLACE package BODY get_all_inventory_package is
procedure get_all_inventory (o_return_variable OUT arrayofrec)is
return_variable arrayofrec;
begin
select * bulk collect into o_return_variable from Inventory;
end;
END;
/
declare
v_receiver get_all_inventory_package.arrayofrec;
begin
get_all_inventory_package.get_all_inventory(v_receiver);
for a in 1..v_receiver.count loop
dbms_output.put_line(v_receiver(a).Inventory_column);
end loop;
end;