简体   繁体   English

使用%ROWTYPE声明参数的流水线函数

[英]Pipelined function with a parameter declare with %ROWTYPE

I'm trying to declare a pipelined table function ( t ) inside a package that takes an argument declared as <tablename>%ROWTYPE . 我正在尝试在一个接受声明为<tablename>%ROWTYPE的参数的包中声明一个流水线表函数( t )。 Declaring that function works and the package compiles without any error. 声明该函数有效,并且程序包编译无任何错误。

But I would like to use this function inside a procedure ( p1 ) like shown below. 但是我想在下面所示的过程( p1 )中使用此函数。

CREATE OR REPLACE PACKAGE BODY t1
AS
   -- private

   PROCEDURE p1
   IS
      l_person   persons%ROWTYPE;
   BEGIN
      FOR l_row IN (SELECT *
                      FROM TABLE (t (l_person)))
      LOOP
         NULL;
      END LOOP;
   END;


   -- public

   FUNCTION t (p_persons_record persons%ROWTYPE)
      RETURN t_a_list
      PIPELINED
   IS
      l_a   t_a;
   BEGIN
      l_a.dummy := 'A';
      PIPE ROW (l_a);
   END;
END;

This sample code does not makes sense but it demonstrates my problem. 此示例代码没有任何意义,但可以说明我的问题。 It just doesn't compile but gives the following errors: 它只是不编译,但会出现以下错误:

[Error] PLS-00382 (10: 38): PLS-00382: expression is of wrong type
[Error] PLS-00306 (10: 35): PLS-00306: wrong number or types of arguments in call to 'T'
[Error] ORA-00904 (10: 35): PL/SQL: ORA-00904: "T1"."T": invalid identifier

Can anyone explain what's wrong and how to fix those errors? 谁能解释什么地方出了问题以及如何解决这些错误?

Edit: 编辑:

The package spec is: 套件规格为:

CREATE OR REPLACE PACKAGE t1
AS
   TYPE t_a IS RECORD (dummy VARCHAR2 (1));

   TYPE t_a_list IS TABLE OF t_a;

   FUNCTION t (p_persons_record persons%ROWTYPE)
      RETURN t_a_list
      PIPELINED;
END;

You cannot use a record type in SQL Scope. 您不能在SQL范围中使用记录类型。 So a PL/SQL function with a record parameter derived by rowtype attribute cannot be used as table function in SQL. 因此,具有由rowtype属性派生的记录参数的PL / SQL函数不能用作SQL中的表函数。 The only thing you have to rewrite is to use a SQL object on schema level instead of a PL/SQL record. 您唯一需要重写的就是在架构级别使用SQL对象而不是PL / SQL记录。

-- adapt your columns to your table as necessary
CREATE OR REPLACE TYPE g_persons AS OBJECT (
   ID int,
   C1 int
);

CREATE OR REPLACE PACKAGE t1
AS
   TYPE t_a IS RECORD (dummy VARCHAR2 (1));

   TYPE t_a_list IS TABLE OF t_a;

   FUNCTION t (p_persons_record g_persons_t)
      RETURN t_a_list
      PIPELINED;
END;
/

CREATE OR REPLACE PACKAGE BODY t1
AS
   -- private

   PROCEDURE p1
   IS
      l_person   g_persons_t;
   BEGIN

      l_person.ID := 1; -- init your record some how
      l_person.C1 := 1; -- init your record some how

      FOR l_row IN (SELECT *
                      FROM TABLE (t (l_person)))
      LOOP
         NULL;
      END LOOP;
   END;


   -- public

   FUNCTION t (p_persons_record g_persons_t)
      RETURN t_a_list
      PIPELINED
   IS
      l_a   t_a;

   BEGIN
      l_a.dummy := 'A';
      PIPE ROW (l_a);     
   END;

END;
/

I think your PACKAGE specification lacks t 's declaration. 我认为您的PACKAGE规范缺少t的声明。 Have you checked that your PACKAGE specification is something similar to this?: 您是否检查过PACKAGE规范是否与此相似?:

CREATE OR REPLACE PACKAGE t1 AS
   PROCEDURE p1;
   FUNCTION t (p_persons_record persons%ROWTYPE) RETURN t_a_list PIPELINED;
END;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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