简体   繁体   中英

How to change PL/SQL function call when function is no longer pipelined?

I have PL/SQL function looking like:

FUNCTION get_agent_statistics ( id    NUMBER
      RETURN agent_stats_t
      PIPELINED;

And I select from it (iBatis code):

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

How should I change this select if I'll remove PIPELINED statement from function?

When you remove PIPELINED clause from the function declaration, function ceases to be a PIPELINED table function and as a result you will have to modify the body of the function to convert it to a TABLE function, if you still want to use it the from clause of the query, or a simple function, which you wont be able to use in the from clause of a query.

Addendum

Could I select something from non-pipelined function?

Yes, if you have a TABLE function, otherwise no. Here is a couple of examples:

-- 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> 

If you'll get working compiled procedure without PIPELINED statement, you don't need to change your SELECT . See this - http://www.oracle-base.com/articles/misc/pipelined-table-functions.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM