Cannot select V$SESSION in before LOGOFF trigger

Do you know why I cannot compile this trigger?

CREATE OR REPLACE TRIGGER LOGOFF_TRIGGER
BEFORE LOGOFF ON DATABASE
DECLARE
BEGIN
  insert into TEST
  (USERNAME)
  select distinct USERNAME
  from V$SESSION;
END;
/
LVL 5
ZopiloteAsked:
Who is Participating?
 
sdstuberConnect With a Mentor Commented:
whomever owns the trigger doesn't have select access on v$session.

I was able to compile your trigger fine and it ran correctly as well.
0
 
joebednarzCommented:
Not sure "why" it does that... but try this instead:

create trigger logoff_trigger
before logoff on database
begin
  insert into test values(sys_context('userenv','session_user'));
end;
/
0
 
ZopiloteAuthor Commented:
Problem solved. No direct grant.
0
 
sdstuberCommented:
sorry, didn't see your post.  yes, you are correct, that's "why"

sys_context is a good workaround too
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.