SYS_CONTEXT in a Procedure
I can use the following SQL statement to get the OS_USER from Oracle.
select sys_context('USERENV','OS_USER') from dual;
However when I try to use this in a procedure and assign the value into a variable, no value is assigned.
select sys_context('USERENV','OS_USER') into v_osuser from dual;
My procedure fails as instead of assigning the OS_USER to v_osuer... os_user is NULL.
Any ideas on why this isn't working? Is there a limitation on the INTO clause or since this is in a procedure?
Thanks.
-mcslain
Re: SYS_CONTEXT in a Procedure
Quote:
Originally posted by mcslain
My procedure fails as instead of assigning the OS_USER to v_osuer... os_user is NULL.
What do you mean "it fails"? It fails with ORA error? It works just as expected for me, here is a simple example:
Code:
SQL> select sys_context('USERENV','OS_USER') from dual;
SYS_CONTEXT('USERENV','OS_USER')
--------------------------------------------------------------------
Administrator
SQL> create or replace procedure foo
2 as
3 dummy varchar2(50);
4 begin
5 select sys_context('USERENV','OS_USER') into dummy from dual;
6 dbms_output.put_line('OS user returned by proc: ' || dummy);
7 end;
8 /
Procedure created.
SQL> set serveroutput on
SQL> begin
2 foo;
3 end;
4 /
OS user returned by proc: Administrator
PL/SQL procedure successfully completed.
SQL>