如何确认数据库是 Oracle 及其使用 SQL 的版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/101184/
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
How can I confirm a database is Oracle & what version it is using SQL?
提问by modius
I'm building an installer for an application. The user gets to select a datasource they have configured and nominate what type of database it is. I want to confirm that the database type is indeed Oracle, and if possible, what version of Oracle they are running by sending a SQL statement to the datasource.
我正在为应用程序构建安装程序。用户可以选择他们配置的数据源并指定它是什么类型的数据库。我想通过向数据源发送 SQL 语句来确认数据库类型确实是 Oracle,如果可能,他们正在运行什么版本的 Oracle。
回答by Tony Andrews
Run this SQL:
运行此 SQL:
select * from v$version;
And you'll get a result like:
你会得到这样的结果:
BANNER
----------------------------------------------------------------
Oracle Database 10g Release 10.2.0.3.0 - 64bit Production
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for Solaris: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
回答by Lawrence
Two methods:
两种方法:
select * from v$version;
will give you:
会给你:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
PL/SQL Release 11.1.0.6.0 - Production
CORE 11.1.0.6.0 Production
TNS for Solaris: Version 11.1.0.6.0 - Production
NLSRTL Version 11.1.0.6.0 - Production
OR Identifying Your Oracle Database Software Release:
select * from product_component_version;
will give you:
会给你:
PRODUCT VERSION STATUS
NLSRTL 11.1.0.6.0 Production
Oracle Database 11g Enterprise Edition 11.1.0.6.0 64bit Production
PL/SQL 11.1.0.6.0 Production
TNS for Solaris: 11.1.0.6.0 Production
回答by Ugur
SQL> SELECT version FROM v$instance;
VERSION
-----------------
11.2.0.3.0
回答by Peter Lang
You can either use
您可以使用
SELECT * FROM v$version;
or
或者
SET SERVEROUTPUT ON
EXEC dbms_output.put_line( dbms_db_version.version );
if you don't want to parse the output of v$version.
如果您不想解析 v$version 的输出。
回答by user3362908
If your instance is down, you are look for version information in alert.log
如果您的实例已关闭,您将在 alert.log 中查找版本信息
Or another crude way is to look into Oracle binary, If DB in hosted on Linux, try strings on Oracle binary.
或者另一种粗略的方法是查看 Oracle 二进制文件,如果 DB 托管在 Linux 上,请尝试使用 Oracle 二进制文件上的字符串。
strings -a $ORACLE_HOME/bin/oracle |grep RDBMS | grep RELEASE
回答by Hyman
For Oracle use:
对于 Oracle 使用:
Select * from v$version;
For SQL server use:
对于 SQL 服务器使用:
Select @@VERSION as Version
and for MySQL use:
和 MySQL 使用:
Show variables LIKE "%version%";
回答by Pancho
The following SQL statement:
以下 SQL 语句:
select edition,version from v$instance
returns:
返回:
- database edition eg. "XE"
- database version eg. "12.1.0.2.0"
- 数据库版本例如。“XE”
- 数据库版本例如。“12.1.0.2.0”
(select privilege on the v$instance view is of course necessary)
(当然需要对 v$instance 视图的选择权限)
回答by Lova Chittumuri
We can use the below Methods to get the version Number of Oracle.
我们可以使用下面的方法来获取 Oracle 的版本号。
Method No : 1
方法编号:1
set serveroutput on;
BEGIN
DBMS_OUTPUT.PUT_LINE(DBMS_DB_VERSION.VERSION || '.' || DBMS_DB_VERSION.RELEASE);
END;
Method No : 2
方法编号:2
SQL> select *
2 from v$version;
回答by user2460369
Here's a simple function:
这是一个简单的函数:
CREATE FUNCTION fn_which_edition
RETURN VARCHAR2
IS
/*
Purpose: determine which database edition
MODIFICATION HISTORY
Person Date Comments
--------- ------ -------------------------------------------
dcox 6/6/2013 Initial Build
*/
-- Banner
CURSOR c_get_banner
IS
SELECT banner
FROM v$version
WHERE UPPER(banner) LIKE UPPER('Oracle Database%');
vrec_banner c_get_banner%ROWTYPE; -- row record
v_database VARCHAR2(32767); --
BEGIN
-- Get banner to get edition
OPEN c_get_banner;
FETCH c_get_banner INTO vrec_banner;
CLOSE c_get_banner;
-- Check for Database type
IF INSTR( UPPER(vrec_banner.banner), 'EXPRESS') > 0
THEN
v_database := 'EXPRESS';
ELSIF INSTR( UPPER(vrec_banner.banner), 'STANDARD') > 0
THEN
v_database := 'STANDARD';
ELSIF INSTR( UPPER(vrec_banner.banner), 'PERSONAL') > 0
THEN
v_database := 'PERSONAL';
ELSIF INSTR( UPPER(vrec_banner.banner), 'ENTERPRISE') > 0
THEN
v_database := 'ENTERPRISE';
ELSE
v_database := 'UNKNOWN';
END IF;
RETURN v_database;
EXCEPTION
WHEN OTHERS
THEN
RETURN 'ERROR:' || SQLERRM(SQLCODE);
END fn_which_edition; -- function fn_which_edition
/
Done.
完毕。