如何在 Oracle Database 12c 中 return 多个值
How to return multiple value in Oracle Database 12c
我知道有人问过这个问题
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;
错误信息是 Compilation errors for 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_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
您正在检索对象的一个实例,而不是对象本身。
我刚刚创建了您的功能,对我有用。
我知道有人问过这个问题
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;
错误信息是 Compilation errors for 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_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
您正在检索对象的一个实例,而不是对象本身。 我刚刚创建了您的功能,对我有用。