简体   繁体   English

Oracle 散装收成三列

[英]Oracle bulk collect into three column

How in below function add more than one eg.如何在下面的 function 添加多个例如。 l_col2 and l_col3 l_col2l_col3

l_col2 =  Select sal as val2 from emp where empno = P_ID

l_col3 =  Select deptno as val3 from emp where empno = P_ID

create or replace function F_MY_FUNC
    ( 
         P_ID IN number
       )
          return  sys.odcinumberlist
        as
          l_coll  sys.odcinumberlist;
        begin
          select * bulk collect into l_coll
          from (  
                 Select ename as val from emp where empno = P_ID
                 union all
                 Select ename as val from myemp where empno = P_ID
              );
    
         return l_coll;
       end;

You can, but not into SYS.ODCINUMBERLIST - create your own type.您可以,但不能进入SYS.ODCINUMBERLIST - 创建您自己的类型。

SQL> create or replace type t_row as object
  2    (empno number, ename varchar2(10), job varchar2(10));
  3  /

Type created.

SQL> create or replace type t_tab as
  2    table of t_row;
  3  /

Type created.

SQL> declare
  2    l_tab t_tab;
  3  begin
  4    select t_row(empno, ename, job)      --> 3 columns 
  5      bulk collect into l_tab            --> into one collection
  6      from emp
  7      where deptno = 20;
  8  end;
  9  /

PL/SQL procedure successfully completed.

SQL>

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

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