1.查詢oracle表空間的使用情況
select b.file_id 文件ID,
b.tablespace_name 表空間,
b.file_name 物理文件名,
b.bytes 總字節數,
(b.bytes-sum(nvl(a.bytes,0))) 已使用,
sum(nvl(a.bytes,0)) 剩餘,
sum(nvl(a.bytes,0))/(b.bytes)*100 剩餘百分比
from dba_free_space a,dba_data_files b
where a.file_id=b.file_id
group by b.tablespace_name,b.file_name,b.file_id,b.bytes
order by b.tablespace_name
b.tablespace_name 表空間,
b.file_name 物理文件名,
b.bytes 總字節數,
(b.bytes-sum(nvl(a.bytes,0))) 已使用,
sum(nvl(a.bytes,0)) 剩餘,
sum(nvl(a.bytes,0))/(b.bytes)*100 剩餘百分比
from dba_free_space a,dba_data_files b
where a.file_id=b.file_id
group by b.tablespace_name,b.file_name,b.file_id,b.bytes
order by b.tablespace_name
2.查詢oracle系統用戶的默認表空間和臨時表空間
select default_tablespace,temporary_tablespace from dba_users
3.查詢單張表的使用情況
select segment_name,bytes from dba_segments where segment_name = 'RE_STDEVT_FACT_DAY' and owner = USER
RE_STDEVT_FACT_DAY是您要查詢的表名稱
4.查詢所有用戶表使用大小的前三十名
select * from (select segment_name,bytes from dba_segments where owner = USER order by bytes desc ) where rownum <= 30
5.查詢當前用戶默認表空間的使用情況
select tablespacename,sum(totalContent),sum(usecontent),sum(sparecontent),avg(sparepercent)
from
(
SELECT b.file_id as id,b.tablespace_name as tablespacename,b.bytes as totalContent,(b.bytes-sum(nvl(a.bytes,0))) as usecontent,sum(nvl(a.bytes,0)) as sparecontent,sum(nvl(a.bytes,0))/(b.bytes)*100 as sparepercent
FROM dba_free_space a,dba_data_files b
WHERE a.file_id=b.file_id and b.tablespace_name = (select default_tablespace from dba_users where username = user)
group by b.tablespace_name,b.file_name,b.file_id,b.bytes
)
GROUP BY tablespacename
from
(
SELECT b.file_id as id,b.tablespace_name as tablespacename,b.bytes as totalContent,(b.bytes-sum(nvl(a.bytes,0))) as usecontent,sum(nvl(a.bytes,0)) as sparecontent,sum(nvl(a.bytes,0))/(b.bytes)*100 as sparepercent
FROM dba_free_space a,dba_data_files b
WHERE a.file_id=b.file_id and b.tablespace_name = (select default_tablespace from dba_users where username = user)
group by b.tablespace_name,b.file_name,b.file_id,b.bytes
)
GROUP BY tablespacename
6.查詢用戶表空間的表
select * from user_tables