Oracle使用集锦

常用经典SQL

  • 查看表空间名称及空间使用率
select ts.tablespace_name AS tablespace,
       ts.contents AS TYPE,
       round(size_info.megs_used/1024/1024) AS "used_size(MB)",
      round(  size_info.max/1024/1024) AS "total_size(MB)",
       -- size_info.megs_free AS free_bytes,
     round((max - size_info.megs_used)/1024/1024) AS "free_size(MB)",
       round((megs_used / Max) * 100)||'%' AS used_pct,
       DECODE(ts.status, 'ONLINE', 1, 'OFFLINE', 2, 'READ ONLY', 3, 0) AS status
  From (select a.tablespace_name,
               round(a.bytes_alloc) megs_alloc,
               round(nvl(b.bytes_free, 0)) megs_free,
               round((a.bytes_alloc - nvl(b.bytes_free, 0))) megs_used,
               round((nvl(b.bytes_free, 0) / a.bytes_alloc) * 100) Pct_Free,
               100 - round((nvl(b.bytes_free, 0) / a.bytes_alloc) * 100) Pct_used,
               round(maxbytes) Max
          from (select f.tablespace_name,
                       sum(f.bytes) bytes_alloc,
                       sum(decode(f.autoextensible,
                                  'YES',
                                  f.maxbytes,
                                  'NO',
                                  f.bytes)) maxbytes
                  from dba_data_files f
                 group by tablespace_name) a,
               (select ts.name tablespace_name,
                       sum(fs.blocks) * ts.blocksize bytes_free
                  from DBA_LMT_FREE_SPACE fs, sys.ts$ ts
                 where ts.ts# = fs.tablespace_id
                 group by ts.name, ts.blocksize) b
         where a.tablespace_name = b.tablespace_name(+)
        union all
        select h.tablespace_name,
               round(sum(h.bytes_free + h.bytes_used)) megs_alloc,
               round(sum((h.bytes_free + h.bytes_used) -
                         nvl(p.bytes_used, 0))) megs_free,
               round(sum(nvl(p.bytes_used, 0))) megs_used,
               round((sum((h.bytes_free + h.bytes_used) -
                          nvl(p.bytes_used, 0)) /
                     sum(h.byt
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值