IT技术博客大学习 共学习 共进步
全部 移动开发 后端 数据库 AI 算法 安全 DevOps 前端 设计 开发者

Tips: PL/SQL中监控执行进度两种方法

eagle's home 2009-10-21 09:05:06 累计浏览 3,724 次
本机暂存

    这是我常用的两种PL/SQL监控运行状况的方法:

    1. 使用dbms_application_info.SET_CLIENT_INFO

    举例如下:

以下是代码片段:
    declare
     cursor cr is select rowid from test;
     delete_count number;
     total_count number;
    begin
     delete_count :=0;
     total_count :=0;
     for i in cr loop
     delete from test where rowid=i.rowid;
     delete_count :=delete_count+1;
     total_count :=total_count+1;
     if (delete_count>100) then
     dbms_application_info.SET_CLIENT_INFO(’ So far ‘||total_count||’ rows has been deleted’);
     delete_count :=0;
     commit;
     end if;
     end loop;
    end;
    /

    另开一session, select client_info from v$session where client_info like ‘So far%’;

    注意info的长度有限制,超过64字符会被截断

    2. 使用dbms_system.ksdwrt, 这个可以写到300个字符

    KSDWRT Procedure

    This procedure prints the message to the target file (alert log and/or trace file).

    Syntax

    DBMS_SYSTEM.KSDWRT (

     dest IN BINARY_INTEGER,

     tst IN VARCHAR2);

    Parameters:

    dest Destination is indicated by the following values:

    1 - Write to trace file.

    2 - Write to alertlog.

    3 - Write to both.

    tst Message (not tested for max length, but output with 300 chars was successful)

    举例如下:

以下是代码片段:
    declare
     cursor cr is select rowid from test;
     delete_count number;
     total_count number;
    begin
     delete_count :=0;
     total_count :=0;
     for i in cr loop
     delete from test where rowid=i.rowid;
     delete_count :=delete_count+1;
     total_count :=total_count+1;
     if (delete_count>100) then
     dbms_system.ksdwrt (1,’ So far ‘||total_count||’ rows has been deleted’);
     delete_count :=0;
     commit;
     end if;
     end loop;
    end;
    /

    然后开一session, tail -30f xxx.trc

同分类推荐文章

  1. 第七章 事务 (2026-04-07 08:00:00)
  2. 第六章:分区 (2026-03-29 08:00:00)
  3. Neko Master: 从 0 到 1K+ Star 的 Vibe Coding 实践 (2026-03-01 08:00:00)

查看更多 数据库 文章 →

建议继续学习

  1. Oracle MTS模式下 进程地址与会话信息 (累计阅读 14,307)
  2. 那些在11gR2中可能惹祸的新特性,一张列表帮助你摆脱升级11gR2带来的烦恼 (累计阅读 6,824)
  3. 性能测试工具sysbench简介 (累计阅读 5,961)
  4. 大于2GB的Listener.log和运行超过198天的主机上的Oracle实例 (累计阅读 5,803)
  5. 仅仅只备份是不够的 (累计阅读 5,760)
  6. Oracle Database 12c 新特性 - Native Top N 查询 (累计阅读 5,684)
  7. ORACLE最大可以存储多少数据量 (累计阅读 5,664)
  8. Oracle DBA的学习进阶成长树-从初出茅庐到高瞻远瞩 (累计阅读 5,542)
  9. 老托的Oracle 数据库Patch概念性小常识 (累计阅读 5,470)
  10. 查看oracle数据库用户下的所有空表 (累计阅读 5,443)