【问题标题】:How to return multiple value in Oracle Database 12c如何在 Oracle Database 12c 中返回多个值
【发布时间】:2017-02-01 16:41:17
【问题描述】:

我知道有人问过这个问题

Oracle: Return multiple values in a function

Returning multiple values from an Oracle 12c function

我跟着他们,但它导致错误,我无法编译它。我错过了一些东西,所以我需要帮助。

我的代码是

create or replace type child_type AS OBJECT
(
  child_id_number varchar2(2000),
  child_name varchar2(2000),
  other_id varchar2(2000)
);


        CREATE or replace function children_b
        (
                   i_id_number IN VARCHAR2
        )
        RETURN child_type
        AS

child_record child_type;



    BEGIN

                  SELECT LISTAGG(ch.child_id_number, ', ')WITHIN GROUP (ORDER BY ch.child_id_number),
                         LISTAGG(e.mail_name, ', ')WITHIN GROUP (ORDER BY e.mail_name),
                         LISTAGG(ib.other_id,', ')WITHIN GROUP (ORDER BY ib.other_id)

    INTO child_type.child_id_number,child_type.child_name,child_type.other_id

                         FROM entity e
                         JOIN children ch ON ch.child_id_number = e.id_number
                         JOIN ids_base ib ON ib.id_number = ch.child_id_number
                         WHERE ib.ids_type_code = 'BAN'
                         AND ch.id_number IN (i_id_number)
                         GROUP BY ch.id_number;


        return(child_record);



        End children_b;

错误消息是 FUNCTION TU_ADIS.TU_CHILDREN_B 的编译错误

错误:PLS-00330:类型名称或子类型名称的使用无效 线路:23 文本:INTO child_type.child_id_number,child_type.child_name,child_type.other_id

错误:PL/SQL: ORA-00904: : 无效标识符 线路:24 文本:FROM bio_entity e

错误:PL/SQL:SQL 语句被忽略 线路:20 文本:SELECT LISTAGG(ch.child_id_number, ', ')WITHIN GROUP (ORDER BY ch.child_id_number),

非常感谢。

【问题讨论】:

  • 您的 INTO 子句通过变量的类型而不是名称来引用变量,child_record
  • 谢谢!!!!!!!!!它现在正在工作!!!

标签: oracle function oracle12c


【解决方案1】:

在您的 INTO 子句中更改

child_type.child_id_number,child_type.child_name,child_type.other_id 

child_record.child_id_number,child_record.child_name,child_record.other_id

您正在检索对象的实例而不是对象本身。 我刚刚创建了你的函数,这对我有用。

【讨论】:

  • 非常感谢!!!!!!!现在我在运行该函数时遇到此错误 ORA-06530 Reference to Uninitialized。你知道它是什么吗?
  • 不确定你是如何运行它的,但是函数返回的对象实例需要返回到某个东西中,并且需要初始化。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-14
  • 1970-01-01
  • 1970-01-01
  • 2012-06-06
  • 1970-01-01
相关资源
最近更新 更多