oracle 有没有办法使用 SQL 获取有关服务器的信息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16565829/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:40:04  来源:igfitidea点击:

Is there a way to get information about a server using SQL

sqloraclewindows-server

提问by user2266357

Is there a way to get information about a server using SQL? It is an Oracle database using a windows server. I searched google and all I found was @@versionwhich does not work. Thanks for your help.

有没有办法使用 SQL 获取有关服务器的信息?它是一个使用 Windows 服务器的 Oracle 数据库。我搜索了谷歌,我发现的所有@@version内容都不起作用。谢谢你的帮助。

回答by Francesco De Lisi

Here is a good list of the main informations retrieve routines. Be sure this is the best way to obtain Server infos:

这是主要信息检索例程的良好列表。确保这是获取服务器信息的最佳方式:

Oracle

甲骨文

Version: PL/SQL, TNS versions using with Oracle.

版本:PL/SQL、TNS 版本与 Oracle 一起使用。

SELECT * FROM v$version;
-- Which version of oracle you are running.
SELECT * FROM v$version WHERE banner LIKE 'Oracle%';
-- Or, in more readable way.
SELECT * FROM product_component_version;

Instance: Displays the state of the current instance.

实例:显示当前实例的状态。

SELECT * FROM v$instance;
-- About license limits of the current instance.
SELECT * FROM v$license;

Database: Db Name.

数据库数据库名称。

SELECT * FROM GLOBAL_NAME
--Db IP Address.
SELECT UTL_INADDR.get_host_address FROM dual
--Db Host Name.
SELECT UTL_INADDR.GET_HOST_NAME('above ip address') FROM dual

Client: Client IP Address.

客户端:客户端 IP 地址。

SELECT SYS_CONTEXT('USERENV','IP_ADDRESS') FROM dual
--Db Host Name
SELECT SYS_CONTEXT('USERENV','TERMINAL') FROM dual
--Db Host Name with domain.
SELECT SYS_CONTEXT('USERENV','HOST') FROM dual
--Current Client session details who using DB.
SELECT * FROM v$session WHERE username = 'User/Schema name'
--To which DB user connected to.
SELECT SUBSTR(GLOBAL_NAME, 1, INSTR(GLOBAL_NAME,'.')-1) FROM GLOBAL_NAME

SQL Server

数据库服务器

Version: Which versions of Sql sever you are running.

版本:您正在运行的 Sql 服务器版本。

SELECT @@VERSION
SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY ('edition')
-- SERVERPROPERTY Returns property information about the server instance.

Client: Client details (IP Address, Machine Name, Instance using).

客户端:客户端详细信息(IP 地址、机器名称、实例使用)。

SELECT con.client_net_address as IPAddress,
         sess.host_name as MachineName, sess.program_name as ApplicationName,
         login_name as LoginName
FROM sys.dm_exec_connections con
inner join sys.dm_exec_sessions sess
on con.session_ID=sess.session_ID
WHERE con.session_ID = @@SPID

For more details: http://msdn.microsoft.com/en-us/library/ms174396.aspx

有关更多详细信息:http: //msdn.microsoft.com/en-us/library/ms174396.aspx

回答by Semih Yagcioglu

I really don't know why you are doing this since there are several better ways to get more info of your database, nevertheless:

我真的不知道您为什么要这样做,因为有几种更好的方法可以获取有关数据库的更多信息,但是:

Try this:

尝试这个:

select * from v$version;

If it returns result, it is Oracle.

如果返回结果,则为Oracle

If not try this:

如果没有试试这个:

SELECT @@VERSION

If it returns result it is SQL Server.

如果它返回结果它是SQL Server