对于 12C 及以上版本:
SELECT t.tablespace_name,t.contents,t.status,NVL(df.allocated_bytes,0) allocatedbytes, NVL(df.allocated_bytes,0)-(NVL(f.free_blocks*t.block_size,0)+NVL(df.max_free_bytes,0)+(NVL(unused_free_blocks,0)*t.block_size)) usedBytes,(NVL(f.free_blocks*t.block_size,0)+NVL(df.max_free_bytes,0)+(NVL(unused_free_blocks,0)*t.block_size)) freeBytes, NVL(df.allocated_blocks,0) allocatedBlocks,(NVL(f.free_blocks,0)+NVL(unused_free_blocks,0))+(NVL(df.max_free_bytes,0)/t.block_size) freeBlocks FROM sys.dba_tablespaces t, (select name as tablespace_name,sum(ff.free_blocks) free_blocks from (SELECT t.name, sum(fs.blocks) free_blocks FROM sys.DBA_LMT_FREE_SPACE fs join V$TABLESPACE t on fs.tablespace_id=t.ts# and con_id in (select con_id from V$MYSTAT) GROUP BY t.name union SELECT t.name, sum(fs.blocks) free_blocks FROM sys.DBA_DMT_FREE_SPACE fs join V$TABLESPACE t on fs.tablespace_id=t.ts# and con_id in (select con_id from V$MYSTAT) GROUP BY t.name) ff group by name) f , (select dff.tablespace_name,sum(dff.allocated_bytes) allocated_bytes,sum(dff.max_free_bytes) max_free_bytes, sum(dff.allocated_blocks) allocated_blocks from (select dfs.tablespace_name,dfs.autoextensible, sum(decode(sign(dfs.maxbytes-dfs.bytes),1,dfs.maxbytes,dfs.bytes)) allocated_bytes, sum(decode(sign(dfs.maxbytes-dfs.bytes),1,abs(dfs.maxbytes-dfs.bytes),0)) max_free_bytes, sum(decode(sign(dfs.maxblocks-dfs.blocks),1,dfs.maxblocks,dfs.blocks)) allocated_blocks from dba_data_files dfs group by dfs.tablespace_name,dfs.autoextensible)dff group by dff.tablespace_name)df, (select ts_name,sum(space) unused_free_blocks from dba_recyclebin group by ts_name)rc WHERE t.tablespace_name = f.tablespace_name(+) and t.tablespace_name = df.tablespace_name(+) and t.tablespace_name = rc.ts_name(+) order by tablespace_name