Solved

Alter Sesson set Current_schema = <schema_name> not working

Posted on 2004-03-25
3
3,388 Views
Last Modified: 2007-12-19
I have a logon trigger that seems to be executing when I logon to my database.  I'm trying to set the current_schema at that time and when I run:

    select sys_context('userenv', 'current_schema') from dual;

I see that my current_schema is the users schema (e.g. USER2) and not the one I'm setting it to (e.g. USER1).  This is my trigger:

 CREATE OR REPLACE TRIGGER db_logon
 AFTER logon ON DATABASE WHEN (USER IN ('USER2'))
 BEGIN
 
  execute immediate 'ALTER SESSION SET CURRENT_SCHEMA = USER1';

end;

The user has alter session privileges.  Anyone have any helpful hints??
0
Comment
Question by:ameliam
  • 2
3 Comments
 
LVL 8

Expert Comment

by:Danielzt
ID: 10683116
Please read this:

Within the procedure you can give:
EXECUTE IMMEDIATE 'alter session set current_schema = user_name';
This changes the current schema of the session to the specified schema. Subsequent unqualified references to schema objects during the session will resolve to objects in the specified schema. The setting persists for the duration of the session or until you issue another ALTER SESSION SET CURRENT_SCHEMA statement.
This setting offers a convenient way to perform operations on objects in a schema other than that of the current user without having to qualify the objects with the schema name. This setting changes the current schema, but it does not change the session user or the current user, nor does it give you any additional system or object privileges for the session.
Hence you can make use of this for your requirement. But changing the current user within a procedure is not possible.

it looks it does not change the current_schema variable.
0
 
LVL 8

Accepted Solution

by:
Danielzt earned 125 total points
ID: 10683281

I tried this, it works for me. I am using Oracle 9i R2.

BEGIN
  execute immediate 'ALTER SESSION SET CURRENT_SCHEMA = TEST';
end;
select sys_context('userenv', 'current_schema') from dual

what oracle version are you using?

Bug 2015342  ALTER SESSION SET CURRENT_SCHEMA may not work in definers rights rocedure
Versions confirmed as being affected 8.1.7.2 9.0.1.2  

This issue is fixed in 8.1.7.3 (Server Patch Set)
9.0.1.3 (Server Patch Set)
9.2.0.1 (Base Release)
 
0
 

Author Comment

by:ameliam
ID: 10687762
Ah - I'm using 8.1.5 so that could be the problem.  Not the answer I wanted, but thanks Danielzt.  Back to the drawing board... I can't upgrade our database b/c one of our apps will no longer function (little thing like the ERP system... )

Thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now