SHOW_SPACE儲存過程
TOM 大師的show_space 儲存過程指令碼
create or replace procedure show_space
( p_segname_1 in varchar2,
p_owner_1 in varchar2 default user,
p_type_1 in varchar2 default 'TABLE',
p_space in varchar2 default 'AUTO',
p_analyzed in varchar2 default 'Y'
)
as
p_segname varchar2(100);
p_type varchar2(10);
p_owner varchar2(30);
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;
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;
procedure p( p_label in varchar2, p_num in number )
is
begin
dbms_output.put_line( rpad(p_label,40,'.') ||
p_num );
end;
begin
p_segname := upper(p_segname_1); -- rainy changed
p_owner := upper(p_owner_1);
p_type := p_type_1;
if (p_type_1 = 'i' or p_type_1 = 'I') then --rainy changed
p_type := 'INDEX';
end if;
if (p_type_1 = 't' or p_type_1 = 'T') then --rainy changed
p_type := 'TABLE';
end if;
if (p_type_1 = 'c' or p_type_1 = 'C') then --rainy changed
p_type := 'CLUSTER';
end if;
dbms_space.unused_space
( segment_owner => p_owner,
segment_name => p_segname,
segment_type => p_type,
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 );
if p_space = 'MANUAL' or (p_space <> 'auto' and p_space <> 'AUTO') then
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;
p( 'Total Blocks', l_total_blocks );
p( 'Total Bytes', l_total_bytes );
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 );
/*IF the segment is analyzed */
if p_analyzed = 'Y' then
dbms_space.space_usage(segment_owner => p_owner ,
segment_name => p_segname ,
segment_type => p_type ,
unformatted_blocks => l_unformatted_blocks ,
unformatted_bytes => l_unformatted_bytes,
fs1_blocks => l_fs1_blocks,
fs1_bytes => l_fs1_bytes ,
fs2_blocks => l_fs2_blocks,
fs2_bytes => l_fs2_bytes,
fs3_blocks => l_fs3_blocks ,
fs3_bytes => l_fs3_bytes,
fs4_blocks => l_fs4_blocks,
fs4_bytes => l_fs4_bytes,
full_blocks => l_full_blocks,
full_bytes => l_full_bytes);
dbms_output.put_line(rpad(' ',50,'*'));
dbms_output.put_line('The segment is analyzed');
p( '0% -- 25% free space blocks', l_fs1_blocks);
p( '0% -- 25% free space bytes', l_fs1_bytes);
p( '25% -- 50% free space blocks', l_fs2_blocks);
p( '25% -- 50% free space bytes', l_fs2_bytes);
p( '50% -- 75% free space blocks', l_fs3_blocks);
p( '50% -- 75% free space bytes', l_fs3_bytes);
p( '75% -- 100% free space blocks', l_fs4_blocks);
p( '75% -- 100% free space bytes', l_fs4_bytes);
p( 'Unused Blocks', l_unformatted_blocks );
p( 'Unused Bytes', l_unformatted_bytes );
p( 'Total Blocks', l_full_blocks);
p( 'Total bytes', l_full_bytes);
end if;
end;
/
使用示例
SQL> set serverout on
SQL> exec show_space('TAB_HIS');
Total Blocks............................1152
Total Bytes.............................9437184
Unused Blocks...........................64
Unused Bytes............................524288
Last Used Ext FileId....................4
Last Used Ext BlockId...................3465
Last Used Block.........................64
*************************************************
The segment is analyzed
0% -- 25% free space blocks.............0
0% -- 25% free space bytes..............0
25% -- 50% free space blocks............0
25% -- 50% free space bytes.............0
50% -- 75% free space blocks............0
50% -- 75% free space bytes.............0
75% -- 100% free space blocks...........16
75% -- 100% free space bytes............131072
Unused Blocks...........................11
Unused Bytes............................90112
Total Blocks............................1035
Total bytes.............................8478720
PL/SQL procedure successfully completed.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15747463/viewspace-1088952/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle儲存過程乾貨(一):儲存過程基礎Oracle儲存過程
- SQL 儲存過程裡呼叫另一個儲存過程SQL儲存過程
- 儲存過程與儲存函式儲存過程儲存函式
- unidac儲存過程儲存過程
- firedac儲存過程儲存過程
- 呼叫儲存過程儲存過程
- mysql 儲存過程MySql儲存過程
- SQLSERVER儲存過程SQLServer儲存過程
- Oracle儲存過程Oracle儲存過程
- MySQL---------儲存過程MySql儲存過程
- 造數儲存過程儲存過程
- linux呼叫儲存過程Linux儲存過程
- Oracle儲存過程-1Oracle儲存過程
- 儲存過程——遊標儲存過程
- Winform呼叫儲存過程ORM儲存過程
- 儲存過程 傳 datatable儲存過程
- mysql儲存過程整理MySql儲存過程
- JAVA儲存過程(轉)Java儲存過程
- JdbcTemplate調儲存過程JDBC儲存過程
- MySQL之儲存過程MySql儲存過程
- oracle的儲存過程Oracle儲存過程
- Sql儲存過程分頁--臨時表儲存SQL儲存過程
- mybatis儲存過程返回listMyBatis儲存過程
- 資料庫儲存過程資料庫儲存過程
- mysql如何呼叫儲存過程MySql儲存過程
- Mysql 儲存過程的使用MySql儲存過程
- SQL 分頁儲存過程SQL儲存過程
- 原創:oracle 儲存過程Oracle儲存過程
- jsp中呼叫儲存過程JS儲存過程
- mongo 儲存過程詳解Go儲存過程
- Sqlserver中的儲存過程SQLServer儲存過程
- mysql和orcale的儲存過程和儲存函式MySql儲存過程儲存函式
- mssql 儲存過程呼叫另一個儲存過程中的結果的方法分享SQL儲存過程
- Sqlsugar呼叫Oracle的儲存過程SqlSugarOracle儲存過程
- SQL server儲存過程函式SQLServer儲存過程函式
- 儲存過程不好在哪裡?儲存過程
- openGauss 支援儲存過程除錯儲存過程除錯
- mySql 儲存過程與函式MySql儲存過程函式
- plsqlDevloper 儲存過程的除錯SQLdev儲存過程除錯