正如 Tony 已经回答的那样:您无法更改 dbms_output 的行为。
向存储过程外部发送进度信号的推荐方法是使用dbms_application_info 包来管理v$session_longops 中的信息
您甚至可以为外循环和内循环管理单独的进度指示器。 v$session_longops 甚至会根据一段时间内的平均持续时间显示该过程需要多长时间的估计值。如果每个(报告的)步骤的运行时间相当恒定,那么这些估计是非常准确的。
你可以像这样增强你的功能:
create or replace function updatebal(start_date IN DATE, end_date IN DATE)
RETURN NUMBER
IS
difference number;
curr_r number;
main_index binary_integer;
sub_index binary_integer;
main_slno binary_integer;
sub_slno binary_integer;
BEGIN
difference := end_date - start_date;
curr_r := 0;
-- initialize the module information
dbms_application_info.set_module('updatebal', 'Calculate Balance');
-- initialize two different "handles" for the inner and outer loop
main_index := dbms_application_info.set_session_longops_nohint;
sub_index := dbms_application_info.set_session_longops_nohint;
while curr_r <= difference LOOP
curr_r := curr_r + 10;
-- report each outer step
dbms_application_info.set_session_longops(rindex => main_index,
slno => main_slno,
op_name => 'main loop',
sofar => curr_r,
totalwork => difference);
for curr_in in 1..10 LOOP
date_value := date_value +1;
insertAvailBal(date_value);
commit;
select count(*) into totalCount from avail_bal;
-- report each inner step with the totalcount
dbms_application_info.set_session_longops(
rindex => sub_index,
slno => sub_slno,
op_name => 'Sub Loop, totalcount'||totalcount,
sofar => curr_in, totalwork => 10);
end loop;
END LOOP;
RETURN 1;
dbms_application_info.set_module(null,null);
END;
/
查看手册了解更多详情:
https://docs.oracle.com/database/121/ARPLS/d_appinf.htm#ARPLS003