返回数据集合的 APEX Oracle 包

APEX Oracle Package returning a data collection

是否可以在包中从 oracle 数据集合创建 APEX 交互式网格。它不需要是交互式网格,而是任何报告。我有一个带有输出参数(光标)的 pkg,我想在 APEX 页面上显示它。如果可能的话,你能给我举个例子或者提供一些关于如何完成这个的说明吗?谢谢

目前无法使用游标作为 APEX 组件的源。这是因为 APEX 引擎 "wraps" 提供的 SQL 查询具有更多 SQL 以应用过滤器、进行排序、分页等

当存储过程return是游标时,游标已经打开,APEX 引擎无法修改其结果。

您可以考虑以下几种解决方法。两者都不会像为报告提供 SQL 查询那样高效,但如果游标没有 return 大量数据,那么两者都应该可以正常工作。

  1. 考虑使用 APEX Collections。 APEX Collections 不是 PL/SQL collection。它们可以被认为是链接到用户 session 的通用临时 table。在页面加载时,您将编写 PL/SQL 代码来获取光标并使用它来填充 collection。那么报告的 SQL 查询将写在 table.
  2. 之上
  3. 考虑将 API return 的游标换成你自己的 "table function" return 的 PL/SQL collection。然后将编写报告的 SQL 查询以使用 TABLE 函数调用包装器(它将函数调用视为实际的 table)。

下面是创建视图的示例:

-- Create a simple table
create table t (
  c  number,
  c2 varchar2(10)
);

-- Add some data
insert into t (c, c2) values (1, 'one');
insert into t (c, c2) values (2, 'two');
insert into t (c, c2) values (3, 'three');

-- Create a function that returns an opened cursor
create or replace function get_cursor
  return sys_refcursor
is

  l_cursor sys_refcursor;

begin
  open l_cursor for select * from t;

  return l_cursor;
end;
/

-- Create an object type based on a row of the cursor
create type cursor_ot as object(
  c  number,
  c2 varchar2(10)
);
/

-- Create a nested table based on the object type 
create type cursor_ntt is table of cursor_ot;
/

-- Create a pipelined function to fetch the data from the cursor
create or replace function get_piped_data

  return cursor_ntt pipelined

as

  l_cursor sys_refcursor;
  l_c      t.c%type;
  l_c2     t.c2%type;

begin

  l_cursor := get_cursor();

  loop
    fetch l_cursor into l_c, l_c2;
    exit when l_cursor%notfound;

    pipe row(cursor_ot(l_c, l_c2));
  end loop;

  close l_cursor;

end;
/

-- Create a view on the pipelined function
create or replace view t_piped_v
as
select *
from table(get_piped_data());

-- Select data from the view
select *
from t_piped_v;