如何引用oracle中返回表类型的函数的单个元素

如何引用oracle中返回表类型的函数的单个元素,oracle,plsql,Oracle,Plsql,我创建了一个返回表类型的函数,即两列值。我想在通过select语句插入其他表时使用这些单独的列 create or replace type emp_sal as object(empno number,sal number); create or replace nt_emp_sal is table of emp_sal; create or replace function emp_fun(deptno number) return nt_emp_sal is l_nt_emp

我创建了一个返回表类型的函数,即两列值。我想在通过select语句插入其他表时使用这些单独的列

create or replace type emp_sal as object(empno number,sal number);

create or replace nt_emp_sal is table of emp_sal;

create or replace function emp_fun(deptno number) 
return nt_emp_sal 
is
  l_nt_emp_sal nt_emp_sal := nt_emp_sal();
begin
  select emp_sal(empno,sal) bulk collect 
    into l_nt_emp_sal 
    from emp where deptno=p_deptno;
  return l_nt_emp_sal;
end;

基本上,您需要在函数调用周围的查询中使用
TABLE()
关键字,以便像使用任何其他表一样使用结果。根据示例代码,您将编写如下内容:

INSERT INTO ... (colA, colB)
SELECT * FROM TABLE(emp_fun(123))
--            ^^^^^^            ^
从文档:

表函数返回集合类型实例,可以像表一样通过在查询的FROM子句中调用该函数进行查询。Table函数使用Table关键字


您可以在以下位置找到详细示例:

以下是相关部分:

SELECT *
FROM   TABLE(get_tab_tf(10))
--     ^^^^^^           ^
ORDER BY id DESC

下面是我的代码:首先我创建了对象类型,然后嵌套表类型在函数return中使用了这个嵌套表类型。创建或替换类型emp_sal作为对象(empno编号,sal编号);创建或替换nt_emp_sal是emp_sal表;创建或替换函数emp_fun(deptno number)返回nt_emp_sal为l_nt_emp_sal nt_emp_sal:=nt_emp_sal();开始从emp中选择emp_sal(empno,sal)批量收集到l_nt_emp_sal,其中deptno=p_deptno;返回l\n t\u emp\sal;结束;请不要使用评论来提供其他详细信息。相反,编辑你的问题。我是为你做的。如果需要,请随时查看这些更改和/或进一步编辑您的问题。感谢Sylvain的快速回复reply@Rajus很高兴帮助你。如果您觉得这有帮助,请随时联系。这是StackOverflow上表达“谢谢”的主要方式。
SELECT *
FROM   TABLE(get_tab_tf(10))
--     ^^^^^^           ^
ORDER BY id DESC