I think the following function would be more general.
create or replace function search_get_community_name(
v_package_id in integer)
return varchar2
is
v_community_name apm_packages.instance_name%TYPE;
begin
select pretty_name into v_community_name
from dotlrn_communities_all dca,
(select object_id
from site_nodes
connect by prior parent_id = node_id start with object_id = v_package_id) sn
where dca.package_id = sn.object_id;
return v_community_name;
end;
/
show errors