From Oracle 10g, CURRENT_USER , as used in response to Gary Myers , is not recommended. Oracle recommends using the SESSION_USER parameter instead, which:
For enterprise users, returns a schema. For other users, the database username with which the current user is authenticated is returned. This value remains unchanged throughout the session.
I would use CURRENT_SCHEMA. There are subtle differences between the two, because CURRENT_SCHEMA changes if an ALTER SESSION SET CURRENT_SCHEMA statement is issued.
There is also no need to choose from double; You can assign the return value of SYS_CONTEXT directly to a variable.
DECLARE v_current_schema varchar2(30); BEGIN v_current_schema := SYS_CONTEXT('USERENV', 'CURRENT_SCHEMA'); dbms_output.put_line('I am using the schema [' || v_current_schema || ']'); END;
Tom W.
source share