检查oracle sid和数据库名称
我想检查 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我认为 SELECT user FROM Dual; 应该为您提供当前用户
实例名称
和 SELECT sys_context('userenv','instance_name') FROM Dual;我相信您的 可以通过
SELECT sys_context('USERENV', 'SID') FROM DUAL;
获取 SIDI 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;
如果像我一样,您的目标是获取数据库主机和 SID 以生成 Oracle JDBC url,则
以下命令将有所帮助:
用于检查 SID(或实例名称)的 Oracle 查询命令:
用于检查数据库名称(或服务器主机):
Att。
塞尔吉奥·马塞洛
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
为了完整起见,您还可以使用 ORA_DATABASE_NAME。
值得注意的是,并非所有方法都会提供相同的输出:
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:
V$视图主要是系统指标的动态视图。它们用于性能调整、会话监控等。因此默认情况下,访问权限仅限于 DBA 用户,这就是您收到
ORA-00942
的原因。查找数据库名称的最简单方法是:
该视图被授予 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:
This view is granted to PUBLIC, so anybody can query it.
在
sqlplus
命令提示符下输入,然后您将在命令提示符下看到结果
这里第一个“ORCL”是数据库名称,可能是您的系统“XE”以及其他在oracle下载时给出的内容。
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.
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;
正如上面已经提到的,
这是要走的路。
您无法查询 v$database/v$instance/v$thread,因为您的用户没有所需的权限。您可以通过以下方式授予它们(通过 DBA 帐户):
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:
从 Dual 中选择 sys_context('userenv','instance_name');
SELECT sys_context('userenv','instance_name') FROM dual;