Default Schema in Oracle Connection URL

netic picture netic · Mar 1, 2010 · Viewed 77k times · Source

I'd like to set default database schema in Oracle Connection URL

jdbc:oracle:thin:@<server>:<port1521>:<sid>

My sample SQL statement:

select monkey_name from animals.monkey

I need to query database without schema prefix animals. i.e. when I run this statement

select monkey_name from monkey

it will use animals schema by default.

What do I need to specify in connection URL above get such effect?

Thanks.

Answer

Gary Myers picture Gary Myers · Mar 1, 2010

You can't put anything in the connection URL.

In Oracle each user has their own schema (even if doesn't contain any objects) and that is their default schema. Once logged in/connected, they can change their default schema with an

ALTER SESSION SET CURRENT_SCHEMA=animals

So you'd need to do the extra statement after connecting. It is possible to have a logon trigger on the user and/or database that will run this when they log in. I'd personally prefer an explicit statement when an application connects.