Skip to Main Content

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Praveen.

Asked: October 21, 2009 - 2:31 pm UTC

Last updated: October 22, 2009 - 3:06 pm UTC

Version: oracle 10g

Viewed 10K+ times! This question is

You Asked

I see lot of Q&A are happening on AFTER LOGON Trigger

I still Could not make the the thing clear to me as i tried them and got failed.

I have normal DB user and SYS user

I want to chnge NLS_SORT option on Normal DB user on this AFTER LOGON Trigger


Could you please help me with the steps which user should do what



ps : I did tried writing the trigger using normal user
got Privilge error

but when i tried with SYS user i got ORA-00900

So i thought would try with your steps


Thanks
Praveen

and Tom said...

there is no such thing as a normal database user, there are users you create and you grant them some (unknown to me) set of privileges.

YOU SHOULD NEVER AND YOU WILL NEVER AGAIN USE THE SYS OR SYSTEM ACCOUNT for your application bits and pieces - never, just stop it, pretend they do not exist.


If your trigger was simply:

"after logon on schema"

then your account would need

a) create session
b) create trigger

if your trigger was

"after logon on database"

then your account would also need

c) administer database trigger


for example:

ops$tkyte%ORA10GR2> create user a identified by a;

User created.

ops$tkyte%ORA10GR2> grant create session, create trigger to a;

Grant succeeded.

ops$tkyte%ORA10GR2>
ops$tkyte%ORA10GR2> connect a/a
Connected.
a%ORA10GR2> alter session set nls_sort = 'binary';

Session altered.

a%ORA10GR2> create or replace trigger after_logon
  2  after logon on schema
  3  begin
  4          execute immediate 'alter session set nls_sort = ''binary_ci''';
  5  end;
  6  /

Trigger created.

a%ORA10GR2> select * from nls_session_parameters where parameter = 'NLS_SORT';

PARAMETER                      VALUE
------------------------------ ----------------------------------------
NLS_SORT                       BINARY

a%ORA10GR2> connect a/a
Connected.
a%ORA10GR2> select * from nls_session_parameters where parameter = 'NLS_SORT';

PARAMETER                      VALUE
------------------------------ ----------------------------------------
NLS_SORT                       BINARY_CI

<b>that shows that

a) I can create the trigger
b) I can execute the trigger code without fail
c) the code in the trigger worked

</b>

a%ORA10GR2> drop trigger after_logon;

Trigger dropped.

a%ORA10GR2> create or replace trigger after_logon
  2  after logon on database
  3  begin
  4          execute immediate 'alter session set nls_sort = ''binary_ci''';
  5  end;
  6  /
after logon on database
               *
ERROR at line 2:
ORA-01031: insufficient privileges


<b>that shows I cannot create a database trigger - you do not actually say what you were doing so I presume this is what you were trying...</b>

a%ORA10GR2> connect /
Connected.
ops$tkyte%ORA10GR2> grant administer database trigger to a;

Grant succeeded.

ops$tkyte%ORA10GR2> select * from nls_session_parameters where parameter = 'NLS_SORT';

PARAMETER                      VALUE
------------------------------ ----------------------------------------
NLS_SORT                       BINARY

ops$tkyte%ORA10GR2> connect a/a
Connected.
a%ORA10GR2> create or replace trigger after_logon
  2  after logon on database
  3  begin
  4          execute immediate 'alter session set nls_sort = ''binary_ci''';
  5  end;
  6  /

Trigger created.

<b>that shows I can and....</b>

a%ORA10GR2> connect /
Connected.
ops$tkyte%ORA10GR2> select * from nls_session_parameters where parameter = 'NLS_SORT';

PARAMETER                      VALUE
------------------------------ ----------------------------------------
NLS_SORT                       BINARY_CI

<b>that it works</b>






if you do this, create the A account, install the trigger, and then LOCK that account, administer database trigger is a powerful grant, you want to protect that account from access by anyone else.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

A reader, February 06, 2010 - 4:13 am UTC

thanks

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library