Solved

Alter Sesson set Current_schema = <schema_name> not working

Posted on 2004-03-25
3
3,368 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

706 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

18 Experts available now in Live!

Get 1:1 Help Now