功能流水线式(Functions Pipelined)

2019-10-17 22:47发布

能否请您解释一下这个对我说:我有一个包规范以下,而不是使用Oracle 10g的机身。

TYPE t_fraud_ext IS TABLE OF FI_RPT.FI_Fraud_OBJ;


FUNCTION fraud_ext_Sql
(   schema_name  IN VARCHAR2
, select_beginning_business_date     IN DATE     – Start Date
, select_thru_business_date  IN DATE     – End Date
, select_beginning_business_time     IN VARCHAR2     – Start Time
, select_thru_business_time  IN VARCHAR2     – End Time
) RETURN VARCHAR2;



FUNCTION fraud_ext
(   schema_name  IN VARCHAR2
, select_beginning_business_date     IN DATE     – Start Date
, select_thru_business_date  IN DATE     – End Date
, select_beginning_business_time     IN VARCHAR2     – Start Time
, select_thru_business_time  IN VARCHAR2     – End Time
) RETURN t_fraud_ext PIPELINED;

如何将这些有关系吗? 从未与管道函数工作。

我也愿意就如何在包装规格/机身采用流水线功能非常详细的例子。

谢谢

Answer 1:

给您只有规范,我们不能告诉如果fraud_ext_Sql被称为fraud_ext ,但它在流水线功能的情况下是不相关的。

使用开始与碱阵列/嵌套表类型的流水线功能。 例如:

SQL> create type test_typ as object (id number, txt varchar2(20));
  2  /

Type created.

SQL> create type test_tab as table of test_typ;
  2  /

Type created.

所以test_tab将在流水线输出中使用。 我们可以有一个标量数组/嵌套表了。 例如,这也将是有效的具有流水线功能的使用方法:

SQL> create type test_tab as table of varchar2(20);
  2  /

Type created.

一旦你有你的基本类型,您定义的功能流水线。 在下面的例子中,我包封在包中的功能,但是这不是必需的; 单机功能可以太习惯。

SQL> create package test_pkg
  2  as
  3    function get_data(p_id number)
  4    return test_tab pipelined;
  5  end;
  6  /

Package created.

pipelined的关键字是关键。 封装体是像下面:

SQL> create package body test_pkg
  2  as
  3
  4    function get_data(p_id number)
  5    return test_tab pipelined
  6    is
  7    begin
  8      for idx in 1..p_id
  9      loop
 10        pipe row(test_typ(idx, dbms_random.string('x', 2)));
 11      end loop;
 12    end get_data;
 13
 14  end;
 15  /

Package body created.

PIPE ROW命令泵行返回给客户端。 这(不像普通功能)紧跟着行返回给客户端(即它不会等待整套发送回行前兑现),你会看到行回来通过在客户端的ARRAYSIZE设置控制批次。 这有甲骨文不需要发送数据返回给客户端之前,保留在内存中整个阵列的优势。

所以给你打电话使用流水线功能table功能如下所示:

SQL> select *
  2    from table(test_pkg.get_data(10));

        ID TXT
---------- --------------------
         1 3B
         2 AM
         3 1J
         4 36
         5 8I
         6 BM
         7 LS
         8 ON
         9 5Z
        10 D7

10 rows selected.

如果你有一个标量数组,就像我assuded之前,该pipe row命令只是有没有直接在任何类型名称值:

SQL> create type test_tab as table of varchar2(20);
  2  /

Type created.

SQL>
SQL> create package test_pkg
  2  as
  3    function get_data(p_id number)
  4    return test_tab pipelined;
  5  end;
  6  /

Package created.

SQL> create package body test_pkg
  2  as
  3
  4    function get_data(p_id number)
  5    return test_tab pipelined
  6    is
  7    begin
  8      for idx in 1..p_id
  9      loop
 10        pipe row(dbms_random.string('x', 2));
 11      end loop;
 12    end get_data;
 13
 14  end;
 15  /

Package body created.

SQL> select *
  2    from table(test_pkg.get_data(10));

COLUMN_VALUE
--------------------
GS
MJ
PF
D6
NG
WO
22
MV
96
8J


文章来源: Functions Pipelined
标签: oracle10g