You can rewrite your query to inner joins instead of sub selects.
select a.actionid,a.actionname,a.allowwrite,a.allowread from thp.tbaction a , thp.tbaction_profile ap , thp.tbprofile p, thp.tbuser u where a.actionid = ap.actionid and ap.profid = p.profid and p.profid = u.profid and u.userid=P_USERID
You don't need to commit after a select statement.
You have a couple of ways to return results from your procedure:
Ref Cursor
this will work only if your application knows how to handle cursors. jdbc\odbc does.
create or replace function select_action (
p_userid in number)
is
result sys_refcursor;
begin
open result for
select a.actionid,a.actionname,a.allowwrite,a.allowread
from thp.tbaction a ,
thp.tbaction_profile ap ,
thp.tbprofile p,
thp.tbuser u
where a.actionid = ap.actionid
and ap.profid = p.profid
and p.profid = u.profid
and u.userid=P_USERID;
if not result%found then
raise_application_error(-20001 , 'user ' || p_userid ||' not found')
end if;
return result;
end;
Temporary table
you insert the result into a global temp table. when the application wants result - it activates the function and then query the result temp table using the user_id
create global temporary table temp_select_action_result
as
select a.actionid,a.actionname,a.allowwrite,a.allowread
from thp.tbaction a
where 1 = 0
procedure select_action (
p_userid in number)
is
begin
insert into temp_select_action_result
select a.actionid,a.actionname,a.allowwrite,a.allowread
from thp.tbaction a ,
thp.tbaction_profile ap ,
thp.tbprofile p,
thp.tbuser u
where a.actionid = ap.actionid
and ap.profid = p.profid
and p.profid = u.profid
and u.userid=P_USERID;
end;