没有游标或循环的Oracle函数

时间:2018-07-18 15:11:38

标签: java oracle hibernate jpa

嗨,我需要知道是否存在一种在oracle中创建函数的方法,该函数可以从查询中返回所有行,例如“ SELECT * FROM FOO”,而无需使用游标或循环。

1 个答案:

答案 0 :(得分:0)

...好吧,下面的函数既不使用游标也不循环,也不返回表中的数据。我使用了bulk collect

create table t(id, name) as (select 1, 'PQR' from dual union all select 2, 'XYZ' from dual);
create type tr as object (id int, name varchar2(10));
create type tt as table of tr;

create or replace function test return tt is
  v_ret tt;
begin
  select tr(id, name) bulk collect into v_ret from t;
  return v_ret;
end;

select * from table(test);

结果:

ID  NAME
--- ----------
  1 PQR
  2 XYZ
相关问题