我有这个查询:
select segment_name,owner,blocks*8192/1024/1024 as MB,tablespace_name
from dba_segments
where segment_name like 'AUD_2%' and owner like 'AUDITOR'
order by 1 desc;
SEGMENT_NAME OWNER MB TABLESPACE_NAME
---------------- ---------- ---------- ----------------
AUD_201304 AUDITOR 7 WSS
AUD_201303 AUDITOR 12 WSS
AUD_201302 AUDITOR 11 WSS
如何添加计数(*)列?
我猜一个相关的子查询会做,但究竟如何?
谢谢 !
抱歉在stackoverflow上找到了代码,下次应该更好地搜索。谢谢
抱歉,这里是解决方案的链接: How to count(*) of multiple tables, size and tablespace in one query
这里是代码:
SELECT ut.table_name,
to_number(extractvalue(xmltype (dbms_xmlgen.getxml ('select count(*) c from ' ||ut.table_name)),'/ROWSET/ROW/C')) row_count,
db.blocks*8192/1024/1024 as MB,
db.tablespace_name
FROM user_tables ut
join dba_segments db on db.segment_name = ut.table_name
WHERE ut.table_name LIKE 'AUD_2%' and owner like 'AUDITOR'
ORDER BY ut.table_name DESC;
这里是输出:
TABLE_NAME ROW_COUNT MB TABLES
------------------------------ ---------- ---------- ------
AUD_201304 21067 7 WSS
AUD_201303 43198 12 WSS
AUD_201302 39046 11 WSS
AUD_201301 44523 17 WSS
AUD_201212 50580 15 WSS
AUD_201211 49589 14 WSS