当函数不再流水线时如何更改PL / SQL函数调用?

时间:2013-07-17 08:33:34

标签: sql oracle function plsql pipelined-function

我的PL / SQL函数看起来像:

FUNCTION get_agent_statistics ( id    NUMBER
      RETURN agent_stats_t
      PIPELINED;

我从中选择(iBatis代码):

    SELECT * FROM table(pkg.get_agent_statistics(#id#))

如果我从函数中删除PIPELINED语句,我应该如何更改此选择?

2 个答案:

答案 0 :(得分:0)

当您从函数声明中删除PIPELINED子句时,函数将不再是PIPELINED表函数,因此您必须修改函数体以将其转换为TABLE函数,如果您仍然想要使用查询的from子句,或者一个简单的函数,它不能在查询的from子句中使用。

<强>附录

Could I select something from non-pipelined function?

是的,如果你有一个TABLE函数,否则没有。以下是几个例子:

-- prerequisites
 SQL> create or replace type T_rows as object(
  2    e_name varchar2(21),
  3    e_lname varchar2(21)
  4  )
  5  /

Type created

SQL> create or replace type T_tab is table of t_rows
  2  /

Type created

-- PIPELINED TABLE function

SQL> create or replace function GetEnames
  2  return T_Tab
  3  pipelined
  4  is
  5    l_etab t_tab := t_tab();
  6  begin
  7    for i in (select first_name
  8                   , last_name
  9                 from employees)
 10    loop
 11      pipe row(t_rows(i.first_name, i.last_name));
 12      --l_etab.extend;
 13      --l_etab(l_etab.last) := t_rows(i.first_name, i.last_name);
 14    end loop;
 15    return ;--l_etab;
 16  end;
 17  /

Function created

SQL> select *
  2    from table(getenames)
  3  where rownum <= 5;

E_NAME                E_LNAME
--------------------- ---------------------
Steven                King
Neena                 Kochhar
Lex                   De Haan
Alexander             Hunold
Bruce                 Ernst

-- non-pipelined table function

SQL> create or replace function GetEnames
  2  return T_Tab
  3  
  4  is
  5    l_etab t_tab := t_tab();
  6  begin
  7    for i in (select first_name
  8                   , last_name
  9                 from employees)
 10    loop
 11      --pipe row(t_rows(i.first_name, i.last_name));
 12      l_etab.extend;
 13      l_etab(l_etab.last) := t_rows(i.first_name, i.last_name);
 14    end loop;
 15    return l_etab;
 16  end;
 17  /

Function created

SQL> select *
  2    from table(getenames)
  3  where rownum <= 5;

E_NAME                E_LNAME
--------------------- ---------------------
Steven                King
Neena                 Kochhar
Lex                   De Haan
Alexander             Hunold
Bruce                 Ernst

SQL> 

答案 1 :(得分:0)

如果您在没有PIPELINED语句的情况下使用编译过程,则无需更改SELECT。见这 - http://www.oracle-base.com/articles/misc/pipelined-table-functions.php