Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine a PL/SQL function's schema from within the function

Tags:

oracle

plsql

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?

like image 983
Jeremy Bourque Avatar asked Jun 23 '09 19:06

Jeremy Bourque


1 Answers

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.

like image 190
Gary Myers Avatar answered Sep 24 '22 20:09

Gary Myers