【问题标题】:How to change PL/SQL function call when function is no longer pipelined?当函数不再流水线时如何更改 PL/SQL 函数调用?
【发布时间】:2013-07-17 08:33:34
【问题描述】:

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

FUNCTION get_agent_statistics ( id    NUMBER
      RETURN agent_stats_t
      PIPELINED;

我从中选择(iBatis 代码):

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

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

【问题讨论】:

  • 你找到答案了吗?

标签: sql oracle function plsql pipelined-function


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    当你从函数声明中删除PIPELINED 子句时,函数不再是一个流水线表函数,因此你必须修改函数体以将其转换为表函数,如果你仍然想在查询的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> 
    

    【讨论】:

    • 首先,感谢您的回答!假设我无法控制函数体,只能更改一个选择。我可以从非流水线函数中选择一些东西吗?
    猜你喜欢
    • 1970-01-01
    • 2021-07-26
    • 1970-01-01
    • 2012-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多