Thursday, November 22, 2012

How to find to which database I'm connected?


This is a simple question for a DBA. Use this query for it.

select name from v$database;

But a normal user can use this only if there is select_catalog_role or select privilege on v$database views. What if a user without select privilege on v$database wants to see the database name? Here are the queries that can be used

select dbms_standard.database_name() database from dual;
select sys_context('userenv', 'db_name') from dual;

1 comment:

  1. In Oracle 12c,

    This returns pluggable database name
    select dbms_standard.database_name() database from dual;

    This return container database name
    select sys_context('userenv', 'db_name') from dual;

    ReplyDelete