检查oracle sid和数据库名称

发布于 2024-11-14 18:07:13 字数 270 浏览 3 评论 0原文

我想检查 SID 和当前数据库名称。

我正在使用以下查询来检查 Oracle SID

select instance from v$thread;

,但出现表或视图不存在错误。

我正在使用以下查询来检查当前数据库名称

select name from v$database;

,但表或视图不存在错误即将到来。

对于以上两个问题有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

羞稚 2024-11-21 18:07:13

我认为 SELECT user FROM Dual; 应该为您提供当前用户

实例名称

和 SELECT sys_context('userenv','instance_name') FROM Dual;我相信您的 可以通过 SELECT sys_context('USERENV', 'SID') FROM DUAL; 获取 SID

I presume SELECT user FROM dual; should give you the current user

and SELECT sys_context('userenv','instance_name') FROM dual; the name of the instance

I believe you can get SID as SELECT sys_context('USERENV', 'SID') FROM DUAL;

浮萍、无处依 2024-11-21 18:07:13

如果像我一样,您的目标是获取数据库主机和 SID 以生成 Oracle JDBC url,则

jdbc:oracle:thin:@<server_host>:1521:<instance_name>

以下命令将有所帮助:

用于检查 SID(或实例名称)的 Oracle 查询命令:

select sys_context('userenv','instance_name') from dual; 

用于检查数据库名称(或服务器主机):

select sys_context('userenv', 'server_host') from dual;

Att。
塞尔吉奥·马塞洛

If, like me, your goal is get the database host and SID to generate a Oracle JDBC url, as

jdbc:oracle:thin:@<server_host>:1521:<instance_name>

the following commands will help:

Oracle query command to check the SID (or instance name):

select sys_context('userenv','instance_name') from dual; 

Oracle query command to check database name (or server host):

select sys_context('userenv', 'server_host') from dual;

Att.
Sergio Marcelo

终难遇 2024-11-21 18:07:13

为了完整起见,您还可以使用 ORA_DATABASE_NAME。

值得注意的是,并非所有方法都会提供相同的输出:

SQL> select sys_context('userenv','db_name') from dual;

SYS_CONTEXT('USERENV','DB_NAME')
--------------------------------------------------------------------------------
orcl

SQL> select ora_database_name from dual;

ORA_DATABASE_NAME
--------------------------------------------------------------------------------
ORCL.XYZ.COM

SQL> select * from global_name;

GLOBAL_NAME
--------------------------------------------------------------------------------
ORCL.XYZ.COM

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:

SQL> select sys_context('userenv','db_name') from dual;

SYS_CONTEXT('USERENV','DB_NAME')
--------------------------------------------------------------------------------
orcl

SQL> select ora_database_name from dual;

ORA_DATABASE_NAME
--------------------------------------------------------------------------------
ORCL.XYZ.COM

SQL> select * from global_name;

GLOBAL_NAME
--------------------------------------------------------------------------------
ORCL.XYZ.COM
征棹 2024-11-21 18:07:13

V$视图主要是系统指标的动态视图。它们用于性能调整、会话监控等。因此默认情况下,访问权限仅限于 DBA 用户,这就是您收到 ORA-00942 的原因。

查找数据库名称的最简单方法是:

select * from global_name;

该视图被授予 PUBLIC,因此任何人都可以查询它。

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:

select * from global_name;

This view is granted to PUBLIC, so anybody can query it.

萌酱 2024-11-21 18:07:13

sqlplus命令提示符下输入

SQL> select * from global_name;

,然后您将在命令提示符下看到结果

SQL ORCL.REGRESS.RDBMS.DEV.US.ORACLE.COM

这里第一个“ORCL”是数据库名称,可能是您的系统“XE”以及其他在oracle下载时给出的内容。

Type on sqlplus command prompt

SQL> select * from global_name;

then u will be see result on command prompt

SQL ORCL.REGRESS.RDBMS.DEV.US.ORACLE.COM

Here first one "ORCL" is database name,may be your system "XE" and other what was given on oracle downloading time.

愛放△進行李 2024-11-21 18:07:13

SID 似乎是 Oracle 环境中的一个重载术语。
关于该主题有很多答案:
SID = SELECT sys_context('USERENV', 'SID') FROM DUAL;

但请注意,这显示了您当前的 session_id,并且每个新的数据库连接都会发生变化。

当在同一问题中引​​用 SID 和当前数据库名称时,可以安全地假设 OP 正在尝试在 tnsnames 或其他地方配置连接,而不是尝试识别当前连接会话的 session_id。

因此在这种情况下:
SID = SELECT sys_context('userenv','instance_name') FROM Dual;

SERVICE_NAME = select sys_context('userenv','service_name') from Dual;

SID appears to be an overloaded term in the Oracle environment.
There's lots of answers on topic which say:
SID = SELECT sys_context('USERENV', 'SID') FROM DUAL;

However please note that this shows your current session_id, and changes for every new connection to the DB.

When referring to SID and current database name in the same question one can safely assume that the OP is trying to configure connections in tnsnames or elsewhere, and not trying to identify the session_id of a currently connected session.

Therefore in this context:
SID = SELECT sys_context('userenv','instance_name') FROM dual;

SERVICE_NAME = select sys_context('userenv','service_name') from dual;

探春 2024-11-21 18:07:13

正如上面已经提到的,

select global_name from global_name;

这是要走的路。

您无法查询 v$database/v$instance/v$thread,因为您的用户没有所需的权限。您可以通过以下方式授予它们(通过 DBA 帐户):

grant select on v$database to <username here>;

As has been mentioned above,

select global_name from global_name;

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:

grant select on v$database to <username here>;
拥有 2024-11-21 18:07:13

从 Dual 中选择 sys_context('userenv','instance_name');

SELECT sys_context('userenv','instance_name') FROM dual;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文