专著oracle 技术 记录维护生产数据库的点点滴滴....

PL/SQL中监控执行进度两种方法 --转载

上一篇 / 下一篇  2007-12-28 00:00:00 / 个人分类:Oracle Developer

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

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

这是我常用的两种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

Table KSDWRT Procedure Parameters

Parameter

Description

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;
/


TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2008-10-12  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 9432
  • 日志数: 674
  • 建立时间: 2007-12-21
  • 更新时间: 2008-10-11

RSS订阅

Open Toolbar