tags:

views:

259

answers:

2

I have a PL/SQL package in an Oracle 10g database and I want to write a function that returns the name of the schema that the package (and hence the function) is defined in. Anyone know how to do this?

A: 

There is probably an easier way but you could use dbms_utility.format_call_stack and parse the results to get the schema name. This works in Oracle 9i.

darreljnz
+2  A: 
create function xcurr return varchar2 is
  v_curr varchar2(32);
begin
  SELECT SYS_CONTEXT ('USERENV', 'CURRENT_USER') into v_curr from dual;
  return v_curr;
end;

This will work as long as the PL/SQL object doesn't have AUTHID CURRENT_USER.

Gary
Wow. I knew about that, but expected it to return the current user, not the user that the function was running as. Thanks!
jbourque