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 > create table t  as  select * from dba_objects;

Table created.

SQL > set serverout on
SQL > exec show_space('T', 'TEST');
Total Blocks .. .. .. .. .. .. .. .. .. .. .. .. .. .. 768
Total Bytes .. .. .. .. .. .. .. .. .. .. .. .. .. .. .6291456
Unused Blocks .. .. .. .. .. .. .. .. .. .. .. .. .. .52
Unused Bytes .. .. .. .. .. .. .. .. .. .. .. .. .. .. 425984
Last Used Ext FileId .. .. .. .. .. .. .. .. .. .. 4
Last Used Ext BlockId .. .. .. .. .. .. .. .. .. .1033
Last Used Block .. .. .. .. .. .. .. .. .. .. .. .. .76
** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** *
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...........0
75% -- 100% free space bytes............0
Unused Blocks .. .. .. .. .. .. .. .. .. .. .. .. .. .0
Unused Bytes .. .. .. .. .. .. .. .. .. .. .. .. .. .. 0
Total Blocks .. .. .. .. .. .. .. .. .. .. .. .. .. .. 696
Total bytes .. .. .. .. .. .. .. .. .. .. .. .. .. .. .5701632

PL
/
SQL procedure successfully completed.

SQL > delete from t;

50602 rows deleted.

SQL > exec show_space('T', 'TEST');
Total Blocks .. .. .. .. .. .. .. .. .. .. .. .. .. .. 768
Total Bytes .. .. .. .. .. .. .. .. .. .. .. .. .. .. .6291456
Unused Blocks .. .. .. .. .. .. .. .. .. .. .. .. .. .52
Unused Bytes .. .. .. .. .. .. .. .. .. .. .. .. .. .. 425984
Last Used Ext FileId .. .. .. .. .. .. .. .. .. .. 4
Last Used Ext BlockId .. .. .. .. .. .. .. .. .. .1033
Last Used Block .. .. .. .. .. .. .. .. .. .. .. .. .76
** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** *
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...........696
75% -- 100% free space bytes............5701632
Unused Blocks .. .. .. .. .. .. .. .. .. .. .. .. .. .0
Unused Bytes .. .. .. .. .. .. .. .. .. .. .. .. .. .. 0
Total Blocks .. .. .. .. .. .. .. .. .. .. .. .. .. .. 0
Total bytes .. .. .. .. .. .. .. .. .. .. .. .. .. .. .0

PL
/
SQL procedure successfully completed.

SQL > alter table t move;

Table altered.

SQL > exec show_space('T', 'TEST');
Total Blocks .. .. .. .. .. .. .. .. .. .. .. .. .. .. 8
Total Bytes .. .. .. .. .. .. .. .. .. .. .. .. .. .. .65536
Unused Blocks .. .. .. .. .. .. .. .. .. .. .. .. .. .5
Unused Bytes .. .. .. .. .. .. .. .. .. .. .. .. .. .. 40960
Last Used Ext FileId .. .. .. .. .. .. .. .. .. .. 4
Last Used Ext BlockId .. .. .. .. .. .. .. .. .. .401
Last Used Block .. .. .. .. .. .. .. .. .. .. .. .. .3
** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** *
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...........0
75% -- 100% free space bytes............0
Unused Blocks .. .. .. .. .. .. .. .. .. .. .. .. .. .0
Unused Bytes .. .. .. .. .. .. .. .. .. .. .. .. .. .. 0
Total Blocks .. .. .. .. .. .. .. .. .. .. .. .. .. .. 0
Total bytes .. .. .. .. .. .. .. .. .. .. .. .. .. .. .0

PL
/
SQL procedure successfully completed

<think>好的,我现在需要帮助用户理解在SQL*Plus中执行`exec zxy_show_space('J_INTENDLATE','TDMSJD1')`的具体作用,以及参数的含义。首先,我需要回忆一下关于Oracle存储过程和`zxy_show_space`的相关知识。 用户提到了引用[2],是关于Oracle 10g存储过程的学习笔记。根据这个信息,`zxy_show_space`很可能是一个自定义的存储过程,用于显示表或索引的存储空间使用情况。通常,这类存储过程会分析对象的空间分配,比如段大小、块使用情况、空闲空间等。类似Oracle内置的`DBMS_SPACE`包中的过程,但可能更简化或定制化。 接下来,参数部分有两个:'J_INTENDLATE'和'TDMSJD1'。通常,存储过程需要对象名称和所有者。第一个参数可能是对象名称,第二个是所有者(schema)。例如,`zxy_show_space(object_name, owner)`。但有时可能顺序相反,需要进一步确认。不过常见的情况是先对象名,后schema,特别是如果该存储过程设计为可能需要跨schema查询的话。 功能方面,执行这个命令可能会输出该对象的空间使用详细信息,比如总块数、已用块、空闲块、行数等,帮助DBA进行空间管理和优化。用户可能想知道这个命令的具体输出是什么,以及如何解读这些信息。同时,可能需要解释存储过程的作用机制,比如是否调用数据字典视图或动态性能视图。 此外,用户可能还需要知道如何创建或获取这个存储过程,因为`zxy_show_space`不是Oracle内置的。可能需要参考引用中的博客,查看是否有相关代码。引用[2]的链接是关于存储过程的学习笔记,可能包含该过程的定义。如果用户没有安装这个过程,执行时会报错,所以可能需要指导用户确认该过程是否存在,或者如何获取并安装它。 最后,用户可能关心参数是否正确,执行后的结果如何解读,以及该命令在数据库迁移或性能优化中的实际应用,比如在TTS传输表空间迁移时分析空间使用情况,如引用[1]提到的迁移案例。需要将功能与实际应用场景结合起来,让用户明白执行此命令的实际意义。</think>在SQL*Plus中执行`exec zxy_show_space('J_INTENDLATE','TDMSJD1')`是调用一个自定义存储过程,用于分析数据库对象的空间使用情况[^2]。以下是具体说明: --- ### **参数含义** 1. **第一个参数 `J_INTENDLATE`** 通常是数据库中的 **表名或索引名**,表示需要分析空间使用情况的具体对象。 2. **第二个参数 `TDMSJD1`** 表示对象的 **所属用户(Schema)**,即该对象在哪个用户下创建。 --- ### **功能说明** `zxy_show_space`的作用是 **显示指定对象的存储空间分配详情**,典型输出可能包括: - **总数据块数**:对象占用的数据块总量 - **已用块数/空闲块数**:实际使用的块与未使用的块 - **行数**:表中存储的数据行数(如果是表) - **扩展区(extent)信息**:对象占用的连续存储区域分配情况 该过程常用于 **性能优化** 或 **存储管理**,例如: - 检测表或索引是否存在空间碎片 - 评估是否需要重建对象以释放空闲空间 - 在数据库迁移前验证存储结构(如TTS传输表空间场景)[^1] --- ### **示例输出** ```sql SQL> exec zxy_show_space('EMPLOYEES','HR'); Total Blocks: 1024 Used Blocks: 768 Free Blocks: 256 Chained Rows: 12 ``` --- ### **注意事项** 1. **依赖权限** 执行该存储过程需要用户对目标对象有`SELECT`权限,并有权访问`DBA_SEGMENTS`等数据字典视图。 2. **自定义过程** `zxy_show_space`并非Oracle内置功能,需通过脚本创建(常见于性能优化工具包或博客示例[^2])。 3. **参数顺序** 若结果不符合预期,可能参数顺序为`(owner, object_name)`,需结合具体实现确认。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值