In Oracle 11g , I am trying to return multiple columns from a function call which is joined with a tables. This function takes employee_id as input and should return first_name and last_name as two separate columns from employees table.
I created a type
create or replace
type mytype as object
( val_1 varchar2(100),
val_2 number
);
/
And function
create or replace
function myfunc(p_in number) return mytype is
v_deptname varchar2(100);
v_mgrid number;
begin
select department_name,manager_id into v_deptname,v_mgrid from DEPARTMENTS where department_id = p_in;
return
mytype(v_deptname,v_mgrid);
end;
/
Both got created successfully. But when I execute function ,
select employee_id, salary, myfunc(department_id) from EMPLOYEES where employee_id in(100,101);
It gives result like below,
EMPLOYEE_ID SALARY
----------- ----------
MYFUNC(DEPARTMENT_ID)(VAL_1, VAL_2)
--------------------------------------------------------------------------------
100 24000
MYTYPE('Executive', 100)
101 17000
MYTYPE('Executive', 100)
But i want my result to be like ,
EMPLOYEE_ID SALARY VAL_1 VAL_2
----------- ---------- ------------------------------ ----------
100 24000 Executive 100
101 17000 Executive 100
Please help to achieve this. Thanks