• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3688
  • Last Modified:

Alter Sesson set Current_schema = <schema_name> not working

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
ameliam
Asked:
ameliam
  • 2
1 Solution
 
DanielztCommented:
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
 
DanielztCommented:

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
 
ameliamAuthor Commented:
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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now