簡體   English   中英

當函數不再流水線化時,如何更改PL / SQL函數調用?

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

我的PL / SQL函數看起來像:

FUNCTION get_agent_statistics ( id    NUMBER
      RETURN agent_stats_t
      PIPELINED;

然后從中選擇(iBatis代碼):

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

如果要從函數中刪除PIPELINED語句,應如何更改此選擇?

當您從函數聲明中刪除PIPELINED子句時,函數不再是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> 

如果在沒有PIPELINED語句的情況下可以使用編譯過程,則無需更改SELECT 看到這個-http://www.oracle-base.com/articles/misc/pipelined-table-functions.php

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM