i have following code in my practice / examples, what if i want to add department_name column to return from this pipelined table function which is not part of employees table, please help how to achieve this?
create or replace type hr.emp_scalar_type as object
(EMPNO NUMBER(4) ,
ENAME VARCHAR2(30),
JOB VARCHAR2(10),
MGR NUMBER(6),
HIREDATE DATE,
SAL NUMBER(8, 2),
COMM NUMBER(4, 2),
DEPTNO NUMBER(4)
)
/
create or replace type hr.emp_table_type as table of hr.emp_scalar_type
/
create or replace function hr.get_emp( p_deptno in number )
return emp_table_type
PIPELINED
as
TYPE EmpCurTyp IS REF CURSOR RETURN hr.employees%ROWTYPE;
emp_cv EmpCurTyp;
l_rec hr.employees%rowtype;
begin
open emp_cv for select * from hr.employees where department_id = p_deptno;
loop
fetch emp_cv into l_rec;
exit when (emp_cv%notfound);
pipe row( emp_scalar_type( l_rec.employee_id, LOWER(l_rec.last_name),
l_rec.job_id, l_rec.manager_id, l_rec.hire_date, l_rec.salary,
l_rec.commission_pct, l_rec.department_id ) );
end loop;
return;
end;
/
select * from table(hr.get_emp(20));
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
201 hartstein MK_MAN 100 17-FEB-04 13000 20
202 fay MK_REP 201 17-AUG-05 6000 20
regards