Bueno, es posible que te falte otro tipo, según MYTYPE
.
Aquí hay un ejemplo (estoy usando el esquema de Scott porque no tengo sus tablas). He añadido DEPTNO
en MYTYPE
para poder unir el resultado (devuelto por la función) con el EMP
mesa.
Esto es lo que tienes:
SQL> create or replace type mytype as object
2 (deptno number,
3 dname varchar2(20),
4 loc varchar2(20));
5 /
Type created.
Esto es lo que te estás perdiendo:
SQL> create or replace type mytab as table of mytype;
2 /
Type created.
Una función:nota línea 9:
SQL> create or replace function myfunc (p_in number) return mytab is
2 v_dname varchar2(20);
3 v_loc varchar2(20);
4 begin
5 select dname, loc
6 into v_dname, v_loc
7 from dept
8 where deptno = p_in;
9 return mytab(mytype(p_in, v_dname, v_loc));
10 end myfunc;
11 /
Function created.
Prueba:
SQL> select * from table(myfunc(10));
DEPTNO DNAME LOC
---------- -------------------- --------------------
10 ACCOUNTING NEW YORK
SQL>
SQL> select e.ename, e.sal, m.dname, m.loc
2 from emp e join table(myfunc(e.deptno)) m on m.deptno = e.deptno
3 where e.deptno = 10
4 order by m.dname, e.ename;
ENAME SAL DNAME LOC
---------- ---------- -------------------- --------------------
CLARK 2450 ACCOUNTING NEW YORK
KING 10000 ACCOUNTING NEW YORK
MILLER 1300 ACCOUNTING NEW YORK
SQL>