create or replace procedure SHOW_SPACE(P_SEGNAME   IN VARCHAR2,

P_OWNER     IN VARCHAR2 DEFAULT USER,

P_TYPE      IN VARCHAR2 DEFAULT 'TABLE',

P_PARTITION IN VARCHAR2 DEFAULT NULL)

-- THIS PROCEDURE USES AUTHID CURRENT USER SO IT CAN QUERY DBA_*

-- VIEWS USING PRIVILEGES FROM A ROLE AND SO IT CAN BE INSTALLED

-- ONCE PER DATABASE, INSTEAD OF ONCE PER USER WHO WANTED TO USE IT.

AUTHID CURRENT_USER AS

L_FREE_BLKS          NUMBER;

L_TOTAL_BLOCKS       NUMBER;

L_TOTAL_BYTES        NUMBER;

L_UNUSED_BLOCKS      NUMBER;

L_UNUSED_BYTES       NUMBER;

L_LASTUSEDEXTFILEID  NUMBER;

L_LASTUSEDEXTBLOCKID NUMBER;

L_LAST_USED_BLOCK    NUMBER;

L_SEGMENT_SPACE_MGMT VARCHAR2(255);

L_UNFORMATTED_BLOCKS NUMBER;

L_UNFORMATTED_BYTES  NUMBER;

L_FS1_BLOCKS         NUMBER;

L_FS1_BYTES          NUMBER;

L_FS2_BLOCKS         NUMBER;

L_FS2_BYTES          NUMBER;

L_FS3_BLOCKS         NUMBER;

L_FS3_BYTES          NUMBER;

L_FS4_BLOCKS         NUMBER;

L_FS4_BYTES          NUMBER;

L_FULL_BLOCKS        NUMBER;

L_FULL_BYTES         NUMBER;

-- INLINE PROCEDURE TO PRINT OUT NUMBERS NICELY FORMATTED

-- WITH A SIMPLE LABEL.

PROCEDURE P(P_LABEL IN VARCHAR2, P_NUM IN NUMBER) IS

BEGIN

DBMS_OUTPUT.PUT_LINE(RPAD(P_LABEL, 40, '.') ||

TO_CHAR(P_NUM, '999,999,999,999'));

END;

BEGIN

-- THIS QUERY IS EXECUTED DYNAMICALLY IN ORDER TO ALLOW THIS PROCEDURE

-- TO BE CREATED BY A USER WHO HAS ACCESS TO DBA_SEGMENTS/TABLESPACES

-- VIA A ROLE AS IS CUSTOMARY.

-- NOTE: AT RUNTIME, THE INVOKER MUST HAVE ACCESS TO THESE TWO

-- VIEWS!

-- THIS QUERY DETERMINES IF THE OBJECT IS AN ASSM OBJECT OR NOT.

BEGIN

EXECUTE IMMEDIATE 'SELECT TS.SEGMENT_SPACE_MANAGEMENT

FROM DBA_SEGMENTS SEG, DBA_TABLESPACES TS

WHERE SEG.SEGMENT_NAME = :P_SEGNAME

AND (:P_PARTITION IS NULL OR

SEG.PARTITION_NAME = :P_PARTITION)

AND SEG.OWNER = :P_OWNER

AND SEG.TABLESPACE_NAME = TS.TABLESPACE_NAME'

INTO L_SEGMENT_SPACE_MGMT

USING P_SEGNAME, P_PARTITION, P_PARTITION, P_OWNER;

EXCEPTION

WHEN TOO_MANY_ROWS THEN

DBMS_OUTPUT.PUT_LINE('THIS MUST BE A PARTITIONED TABLE, USE P_PARTITION => ');

RETURN;

END;

-- IF THE OBJECT IS IN AN ASSM TABLESPACE, WE MUST USE THIS API

-- CALL TO GET SPACE INFORMATION; ELSE WE USE THE FREE_BLOCKS

-- API FOR THE USER MANAGED SEGMENTS.

IF L_SEGMENT_SPACE_MGMT = 'AUTO' THEN

DBMS_SPACE.SPACE_USAGE(P_OWNER,

P_SEGNAME,

P_TYPE,

L_UNFORMATTED_BLOCKS,

L_UNFORMATTED_BYTES,

L_FS1_BLOCKS,

L_FS1_BYTES,

L_FS2_BLOCKS,

L_FS2_BYTES,

L_FS3_BLOCKS,

L_FS3_BYTES,

L_FS4_BLOCKS,

L_FS4_BYTES,

L_FULL_BLOCKS,

L_FULL_BYTES,

P_PARTITION);

P('UNFORMATTED BLOCKS ', L_UNFORMATTED_BLOCKS);

P('FS1 BLOCKS (0-25) ', L_FS1_BLOCKS);

P('FS2 BLOCKS (25-50) ', L_FS2_BLOCKS);

P('FS3 BLOCKS (50-75) ', L_FS3_BLOCKS);

P('FS4 BLOCKS (75-100)', L_FS4_BLOCKS);

P('FULL BLOCKS ', L_FULL_BLOCKS);

ELSE

DBMS_SPACE.FREE_BLOCKS(SEGMENT_OWNER     => P_OWNER,

SEGMENT_NAME      => P_SEGNAME,

SEGMENT_TYPE      => P_TYPE,

FREELIST_GROUP_ID => 0,

FREE_BLKS         => L_FREE_BLKS);

P('FREE BLOCKS', L_FREE_BLKS);

END IF;

-- AND THEN THE UNUSED SPACE API CALL TO GET THE REST OF THE

-- INFORMATION.

DBMS_SPACE.UNUSED_SPACE(SEGMENT_OWNER             => P_OWNER,

SEGMENT_NAME              => P_SEGNAME,

SEGMENT_TYPE              => P_TYPE,

PARTITION_NAME            => P_PARTITION,

TOTAL_BLOCKS              => L_TOTAL_BLOCKS,

TOTAL_BYTES               => L_TOTAL_BYTES,

UNUSED_BLOCKS             => L_UNUSED_BLOCKS,

UNUSED_BYTES              => L_UNUSED_BYTES,

LAST_USED_EXTENT_FILE_ID  => L_LASTUSEDEXTFILEID,

LAST_USED_EXTENT_BLOCK_ID => L_LASTUSEDEXTBLOCKID,

LAST_USED_BLOCK           => L_LAST_USED_BLOCK);

P('TOTAL BLOCKS', L_TOTAL_BLOCKS);

P('TOTAL BYTES', L_TOTAL_BYTES);

P('TOTAL MBYTES', TRUNC(L_TOTAL_BYTES / 1024 / 1024));

P('UNUSED BLOCKS', L_UNUSED_BLOCKS);

P('UNUSED BYTES', L_UNUSED_BYTES);

P('LAST USED EXT FILEID', L_LASTUSEDEXTFILEID);

P('LAST USED EXT BLOCKID', L_LASTUSEDEXTBLOCKID);

P('LAST USED BLOCK', L_LAST_USED_BLOCK);

END;

show_space.sql.txt的更多相关文章

  1. mysql命令行的导入导出sql,txt,excel(都在linux或windows命令行操作)(转自筑梦悠然)

    原文链接https://blog.csdn.net/wuhuagu_wuhuaguo/article/details/73805962 Mysql导入导出sql,txt,excel 首先我们通过命令行 ...

  2. Sql Server海量数据插入

    目录 1.前言 2.BULK INSERT 3.简单示例 前言 由于昨天接到一个客户反馈导出数据卡死的问题,于是决定今天模拟一下千万级的数据,然后傻傻的等待插入数据了半天...... 对于海量数据,上 ...

  3. Navicat Premium下sql导入中文乱码解决方案

    今天帮忙朋友找bug的时候,准备导入她数据库里面的数据,所以我就试图在mysql管理工具Navicat下面导入相应的mysql命令.结果发现导入的中文字符全部变成乱码,所以做了如下这种尝试: 在“连接 ...

  4. 实战手记:让百万级数据瞬间导入SQL Server

    想必每个DBA都喜欢挑战数据导入时间,用时越短工作效率越高,也充分的能够证明自己的实力.实际工作中有时候需要把大量数据导入数据库,然后用于各种程序计算,本文将向大家推荐一个挑战4秒极限让百万级数据瞬间 ...

  5. mysql基础语法及拓展到web中的sql注入

    本来是想写下javaweb的mvc(tomcat, spring, mysql)的搭建,  昨天搭到凌晨3点, 谁知道jdbcTemplate的jar包不好使, 想死的心都有了, 想想还是休息一下, ...

  6. into outfile 生成sql脚本

    select concat('insert into t_dm_stage(STAGE_ID,STAGE_NAME) values(',STAGE_ID,',','\'',STAGE_NAME,'\' ...

  7. 【转 】实战手记:让百万级数据瞬间导入SQL Server

    想必每个DBA都喜欢挑战数据导入时间,用时越短工作效率越高,也充分的能够证明自己的实力.实际工作中有时候需要把大量数据导入数据库,然后用于各种程序计算,本文将向大家推荐一个挑战4秒极限让百万级数据瞬间 ...

  8. 极限挑战—C#100万条数据导入SQL SERVER数据库仅用4秒 (附源码)

    原文:极限挑战-C#100万条数据导入SQL SERVER数据库仅用4秒 (附源码) 实际工作中有时候需要把大量数据导入数据库,然后用于各种程序计算,本实验将使用5中方法完成这个过程,并详细记录各种方 ...

  9. C#100万条数据导入SQL SERVER数据库仅用4秒 (附源码)

    作者: Aicken(李鸣)  来源: 博客园  发布时间: 2010-09-08 15:00  阅读: 4520 次  推荐: 0                   原文链接   [收藏] 摘要: ...

随机推荐

  1. Unity3d IOS中的IGUI控件

    Unity3d IOS中的IGUI控件 @灰太龙  群63438968 我讲一下IOS中用的UI,我们采用IGUI,需要使用IGUI的高版本,在Unity3d 4.2中也可以使用的! 之前IGUI有个 ...

  2. cortex m0 lpc1114的NVIC中断如何使用

    LPC1114单片机的NVIC中断函数,有开中断.关中断.设置优先级.挂起等操作函数.这些函数位于core_cm0.h文件里面.比如开中断的函数如下: /** \brief Enable Extern ...

  3. CreateProcessWithLogonW(好像可以指定进程的上下文环境)

    Creates a new process and its primary thread. Then the new process runs the specified executable fil ...

  4. 修改css

    .content{ height: 100%; } .con{ border: 1px solid #eeeeee; display: inline-block; width:86.8%; ##修改这 ...

  5. 分页SQL模板

    select * from ( select rownum as rn ,a.* from ( select * from page a where object_id >1000 and ow ...

  6. yum命令常见方法

    yum check-update 检查可更新的所有软件包 yum update 下载更新系统已安装的所有软件包 yum upgrade 大规模的版本升级,与yum update不同的是,连旧的淘汰的包 ...

  7. [LeetCode#104, 111]Maximum Depth of Binary Tree, Minimum Depth of Binary Tree

    The problem 1: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes ...

  8. 「Poetize4」上帝造题的七分钟2

    描述 Description "第一分钟,X说,要有数列,于是便给定了一个正整数数列.第二分钟,L说,要能修改,于是便有了对一段数中每个数都开平方(下取整)的操作.第三分钟,k说,要能查询, ...

  9. [Sequence Alignment Methods] Cross-Recurrent Plot (CRP)

    A recurrence plot (RP) is a straightforward way to visualize characteristics of similar system state ...

  10. 尚学堂 JAVA DAY12 java程序执行时内存的分配