直接sql语句:
select wm_concat(decode(e.empno,7369,d.dname,null)),wm_concat(decode(e.empno,7369,e.ename,null)) from emp e, dept d
where e.empno in ((select e1.mgr from emp e1 where e1.empno = 7369), 7369)
and e.deptno = d.deptno
/
function :
create or replace function print_(p_empno in number) return varchar2 is
l_result varchar2(100);
begin
select wm_concat(decode(e.empno, p_empno, d.dname, null)) || ',' ||wm_concat(decode(e.empno, p_empno, e.ename, null))
into l_result
from emp e, dept d
where e.empno in
((select e1.mgr from emp e1 where e1.empno = p_empno), p_empno)
and e.deptno = d.deptno;
return(l_result);
end;
测试:
SQL> select print_(7369) from dual ;
PRINT_(7369)
--------------------------------------------------------------------------------
RESEARCH,SMITH
SQL>