create or replace type Arr as table of varchar2(500);
create or replace function getApproverByRole2(busi_dept_id IN NUMBER,
role_code IN VARCHAR2) RETURN Arr pipelined AS
v_org_id NUMBER;
BEGIN
begin
select org_id
into v_org_id
from sys_dept_ sd
where sd.id = busi_dept_id;
exception
when others then
v_org_id := null;
end;
for person in (SELECT u.*
FROM sys_user_ u,
sys_role_ r,
sys_user_role_ ur,
sys_role_org_ rorg
WHERE u.id = ur.user_id
AND r.id = ur.role_id
AND r.id = rorg.role_id
AND r.role_code = role_code
AND rorg.org_id = v_org_id) loop
pipe row(person.user_name);
end loop;
return;
END;
select column_value from table(cast(getApproverByRole2(1456837,'APP_HR') as Arr ));