0

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

FUNCTION get_agent_statistics ( id    NUMBER
      RETURN agent_stats_t
      PIPELINED;

我从中选择(iBatis 代码):

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

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

4

2 回答 2

0

当您PIPELINED从函数声明中删除子句时,函数不再是流水线表函数,因此,如果您仍想使用它的from子句,则必须修改函数体以将其转换为 TABLE 函数查询,或一个简单的函数,您将无法在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> 
于 2013-07-17T08:52:37.390 回答
0

如果您将在没有PIPELINED声明的情况下获得工作编译过程,则无需更改SELECT. 看到这个 - http://www.oracle-base.com/articles/misc/pipelined-table-functions.php

于 2013-07-17T09:08:36.783 回答