Jaq*_*mbo 7 sql oracle procedure
Oracle SQL过程可以返回一个表吗?我目前正在使用a dbms_output来打印出两个游标的输出,这两个游标在一个循环中,尽管如果它返回两列而看起来会更好.这可能在一个程序中吗?
PL/SQL函数可以返回嵌套表.如果我们将嵌套表声明为SQL类型,我们可以使用TABLE()函数将其用作查询源.
这是一个类型,以及从它构建的嵌套表:
SQL> create or replace type emp_dets as object (
2 empno number,
3 ename varchar2(30),
4 job varchar2(20));
5 /
Type created.
SQL> create or replace type emp_dets_nt as table of emp_dets;
2 /
Type created.
SQL>
Run Code Online (Sandbox Code Playgroud)
这是一个返回嵌套表的函数...
create or replace function get_emp_dets (p_dno in emp.deptno%type)
return emp_dets_nt
is
return_value emp_dets_nt;
begin
select emp_dets(empno, ename, job)
bulk collect into return_value
from emp
where deptno = p_dno;
return return_value;
end;
/
Run Code Online (Sandbox Code Playgroud)
......这就是它的工作原理:
SQL> select *
2 from table(get_emp_dets(10))
3 /
EMPNO ENAME JOB
---------- ------------------------------ --------------------
7782 CLARK MANAGER
7839 KING PRESIDENT
7934 MILLER CLERK
SQL>
Run Code Online (Sandbox Code Playgroud)
SQL类型为我们提供了大量功能,并允许我们在PL/SQL中构建相当复杂的API. 了解更多.