简体   繁体   English

如何使用SQL查询显示Oracle模式大小?

[英]How to display Oracle schema size with SQL query?

I have a Oracle schema with 70+ tables. 我有一个包含70多个表的Oracle模式。 I want to create simple page which can display the HDD space occupied by the tables. 我想创建一个简单的页面,可以显示表占用的硬盘空间。 How I can get this value with SQL query? 我如何用SQL查询获取此值?

PS And how I can get the Oracle architecture version? PS以及我如何获得Oracle架构版本?

You probably want 你可能想要

SELECT sum(bytes)
  FROM dba_segments
 WHERE owner = <<owner of schema>>

If you are logged in as the schema owner, you can also 如果您以架构所有者身份登录,则还可以

SELECT SUM(bytes)
  FROM user_segments

That will give you the space allocated to the objects owned by the user in whatever tablespaces they are in. There may be empty space allocated to the tables that is counted as allocated by these queries. 这将为您提供在用户所拥有的任何表空间中分配给用户所拥有的对象的空间。可能会有空的空间分配给这些查询所分配的表。

If you just want to calculate the schema size without tablespace free space and indexes : 如果您只想计算没有表空间可用空间和索引的模式大小:

select
   sum(bytes)/1024/1024 as size_in_mega,
   segment_type
from
   dba_segments
where
   owner='<schema's owner>'
group by
   segment_type;

For all schemas 对于所有模式

select
   sum(bytes)/1024/1024 as size_in_mega, owner
from
   dba_segments
group by
  owner;
select T.TABLE_NAME, T.TABLESPACE_NAME, t.avg_row_len*t.num_rows from dba_tables t
order by T.TABLE_NAME asc

See eg http://www.dba-oracle.com/t_script_oracle_table_size.htm for more options 有关更多选项,请参见http://www.dba-oracle.com/t_script_oracle_table_size.htm

SELECT table_name as Table_Name, row_cnt as Row_Count, SUM(mb) as Size_MB
FROM
  (SELECT in_tbl.table_name,   to_number(extractvalue(xmltype(dbms_xmlgen.getxml('select count(*) c from ' ||ut.table_name)),'/ROWSET/ROW/C')) AS row_cnt , mb
FROM
(SELECT CASE WHEN lob_tables IS NULL THEN table_name WHEN lob_tables IS NOT NULL THEN lob_tables END AS table_name , mb
FROM (SELECT ul.table_name AS lob_tables, us.segment_name AS table_name , us.bytes/1024/1024 MB FROM user_segments us
LEFT JOIN user_lobs ul ON us.segment_name = ul.segment_name ) ) in_tbl INNER JOIN user_tables ut ON in_tbl.table_name = ut.table_name ) GROUP BY table_name, row_cnt ORDER BY 3 DESC;``

Above query will give, Table_name, Row_count, Size_in_MB(includes lob column size) of specific user. 上面的查询将给出特定用户的Table_name,Row_count,Size_in_MB(包括lob列大小)。

SELECT DS.TABLESPACE_NAME, SEGMENT_NAME, ROUND(SUM(DS.BYTES) / (1024 * 1024)) AS MB
    FROM DBA_SEGMENTS DS
    WHERE SEGMENT_NAME IN (SELECT TABLE_NAME FROM DBA_TABLES) AND SEGMENT_NAME='YOUR_TABLE_NAME'
    GROUP BY DS.TABLESPACE_NAME, SEGMENT_NAME;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在sql developer中计算oracle db中的模式大小? - How to calculate the schema size in oracle db in sql developer? HR Schema 中的 Oracle SQL 编写查询以显示“在第一个 'e' 或 'E' 出现之前,每个员工的姓氏中有多少个字符?” - Oracle SQL in HR Schema Write a query to display “How many characters are there in each employee’s last name before the first 'e' or 'E' appears?” 如何在Oracle SQL查询中不写模式名称? - How to don't write schema name in oracle sql query? 如何在 Oracle 中查找 SQL 查询中返回的记录的 Memory SIZE? - How to find Memory SIZE of records returned in a SQL Query in Oracle? 在 SQL 查询结果中显示 XML 架构 - Display XML Schema in SQL Query Result Oracle SQL Query简化查询涉及多个模式 - Oracle SQL Query Simplification of query a involving multiple schema 如何在查询中创建 SQL 模式? - How to create a SQL Schema in a Query? 在Oracle数据库中查询表/字段时,如何查看查询结果中的表模式? (使用SQuirreL SQL) - When querying tables/fields in Oracle database, how to see table schema in query results? (using SQuirreL SQL) 在 Oracle SQL 中的一个查询中显示 3 个不同的查询 - Display 3 different queries in one query in Oracle SQL Oracle SQL查询-仅显示最大? - Oracle SQL query - Display max only?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM