I want to check SID and current database name.
I am using following query for checking oracle SID
select instance from v$thread;
but table or view does not exist error is coming.
I am using following query for checking current database name
select name from v$database;
but table or view does not exist error is coming.
Any idea for above two problems?
As has been mentioned above,
is the way to go.
You couldn't query v$database/v$instance/v$thread because your user does not have the required permissions. You can grant them (via a DBA account) with:
I presume
select user from dual;
should give you the current userand
select sys_context('userenv','instance_name') from dual;
the name of the instanceI believe you can get SID as
SELECT sys_context('USERENV', 'SID') FROM DUAL;
(can't to check this now)Type on
sqlplus
command promptthen u will be see result on command prompt
Here first one "ORCL" is database name,may be your system "XE" and other what was given on oracle downloading time.
If, like me, your goal is get the database host and SID to generate a Oracle JDBC url, as
the following commands will help:
Oracle query command to check the SID (or instance name):
Oracle query command to check database name (or server host):
Att. Sergio Marcelo
Just for completeness, you can also use ORA_DATABASE_NAME.
It might be worth noting that not all of the methods give you the same output:
The V$ views are mainly dynamic views of system metrics. They are used for performance tuning, session monitoring, etc. So access is limited to DBA users by default, which is why you're getting
ORA-00942
.The easiest way of finding the database name is:
This view is granted to PUBLIC, so anybody can query it.