各个数据库获取数据库资源的SQL语句集合
最近在工作中需要 通过SQL获取很多数据库的资源,故整理了一下这些语句;未列项欢迎留言补充。
获取数据版本号
Oracle:
Select version FROM Product_component_version Where SUBSTR(PRODUCT,1,6)='Oracle'
DB2:
select service_level from table(sysproc.env_get_inst_info()) as instanceinfo
SQLServer:
SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition')
神舟通用(神通):
select version()
SAP HANA:
SELECT VERSION FROM _SYS_EPM.LIBRARY_VERSION
(类Mysql数据库)Mysql、TiDB、OceanBase:
select version()
(类PostgreSQL数据库)PostgreSQL、优炫、Greenplum、MPPDB、GaussDB、HighgoDB:
show server_version
·
·
获取字符集
Oracle:
select value from nls_database_parameters where parameter='NLS_CHARACTERSET'
SQLServer:
SELECT COLLATIONPROPERTY('Chinese_PRC_Stroke_CI_AI_KS_WS', 'CodePage')
神舟通用(神通):
show variables like '%character_set_server%'
(类Mysql数据库)Mysql、TiDB、OceanBase:
show variables like '%character_set_server%'
(类PostgreSQL数据库)PostgreSQL、优炫、Greenplum、MPPDB、GaussDB、HighgoDB:
show server_encoding
·
·
获取Schemas 或 Databases
Oracle:
select a.* from (
select a1.*, rownum rn from (
select distinct a2.owner from all_tables a2 where
a2.owner not in ('SYS','$pm1$','$pm2$')
) a1
) a
where a.rn between $startNum$ and $endNum$
DB2:
SELECT * FROM (
SELECT B.*, ROWNUMBER() OVER() AS TN FROM (
select schemaname, owner, ownertype, definer, definertype from syscat.schemata
) AS B
) AS A WHERE A.TN