Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle setting per user default scheme (not altering a session)

is there a way to change an oracle user's default schema?

I found it in the FAQ that I can alter it in the session, but it's not what I want. E.G. the user at log on always sees another schema as default.

Thanks in advance.

like image 571
Zsolt Botykai Avatar asked Nov 12 '08 10:11

Zsolt Botykai


People also ask

What is default schema in Oracle?

The name of the default schema used by Oracle Database Exadata Express Cloud Service is called the Host Schema and can be found from the Oracle Application Express About option. After identifying the schema name, in order to start using it, you need to set the password for the schema.

Is alter session permanent?

Use the ALTER SESSION statement to set or modify any of the conditions or parameters that affect your connection to the database. The statement stays in effect until you disconnect from the database.

How do I change the schema in Toad?

You can change it in the Query tab, use the "CTRL+F" functional keys to replace the original schema with the new schema, you need to check if they are replaced correctly and then click the Visualize button to see the Diagram, and in the Diagram You can see the columns , and you need to map it again.


3 Answers

I believe a logon trigger should work:

CREATE OR REPLACE TRIGGER db_logon
AFTER logon ON DATABASE WHEN (USER = 'A')
BEGIN
    execute immediate 'ALTER SESSION SET CURRENT_SCHEMA = B';
END;
like image 125
Tony Andrews Avatar answered Oct 29 '22 12:10

Tony Andrews


For some reason Tony's trigger did not work for me. However, a slightly different trigger that I found on the web using the same concept did.

create or replace trigger set_default_schema
after logon on my_user.schema
begin
  execute immediate 'alter session set current_schema=NEW_SCHEMA';
end;

I just wanted to throw it out there in case someone else has the same issue.

like image 12
Ryan Cook Avatar answered Oct 29 '22 10:10

Ryan Cook


create or replace trigger AFTER_LOGON_TSFREL
AFTER LOGON ON "TSFRELEASEAPP".SCHEMA
BEGIN
   EXECUTE IMMEDIATE 'ALTER SESSION SET current_schema=TSF_RELEASE';
END;
like image 1
Greg Avatar answered Oct 29 '22 10:10

Greg