Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SYS_CONTEXT('USERENV','OS_USER')

EdStevensApr 10 2017 — edited Apr 11 2017

Oracle 11.2.0.4.0 SE-One, 64bit

Oracle Linux 6

A couple of years ago I wrote the following trigger:

create or replace TRIGGER "MYORGDBA"."MYORG_AUDIT_LAST_LOGON"

after logon

on database

begin

--

if SYS_CONTEXT('USERENV','SESSION_USER') not in ('SYS') then

  merge into myorgdba.last_user_logon ll

  using (select SYS_CONTEXT('USERENV','SESSION_USER') username,

                SYS_CONTEXT('USERENV','OS_USER') osuser

        from dual

        ) sc

  on (ll.username = sc.username)

  when matched then update set ll.last_logon_date = sysdate,

                               ll.source_ind = 'T',

                               ll.os_username = sc.osuser

  when not matched then insert values (sc.username,

                                       sc.osuser,

                                       sysdate,

                                       'T'

                                       )

;

end if;

end;

With the table

CREATE TABLE "MYORGDBA"."LAST_USER_LOGON"

   (    "USERNAME" VARCHAR2(30 BYTE),

    "OS_USERNAME" VARCHAR2(30 BYTE),

    "LAST_LOGON_DATE" DATE,

    "SOURCE_IND" CHAR(1 BYTE),

     CONSTRAINT "LAST_LOGON_PK" PRIMARY KEY ("USERNAME")

  <snip generated storage clauses> ;

   COMMENT ON COLUMN "MYORGDBA"."LAST_USER_LOGON"."SOURCE_IND" IS 'D - default from initial load; A - initial load, from audit trail; T - from trigger';

Today I began investigating a particular database and noticed that one user is recorded with OS_USERNAME as NULL.  This is not an Oracle internal user, such as DBSNMP or SYSMAN.

So my question is, why would SYS_CONTEXT('USERENV','OS_USER') return null?

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 9 2017
Added on Apr 10 2017
10 comments
1,974 views