[转帖] PL/SQL中监控执行进度两种方法_MySQL, Oracle及数据库讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  MySQL, Oracle及数据库讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 3513 | 回复: 0   主题: [转帖] PL/SQL中监控执行进度两种方法        下一篇 
kim
注册用户
等级:中校
经验:1729
发帖:222
精华:0
注册:2011-7-21
状态:离线
发送短消息息给kim 加好友    发送短消息息给kim 发消息
发表于: IP:您无权察看 2011-8-2 9:26:59 | [全部帖] [楼主帖] 楼主

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




赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论