Stored procedures 有没有办法跟踪oracle函数在数据库中插入的行
我有一个程序来更新从开始日期到结束日期的余额,以及 此外,我还想记录插入的记录数。我使用dbms_output.put_行获取插入的记录数,但它不提供任何输出,当执行完成时,将显示计数的输出。程序守则如下:Stored procedures 有没有办法跟踪oracle函数在数据库中插入的行,stored-procedures,plsql,oracle10g,oracle-sqldeveloper,stored-functions,Stored Procedures,Plsql,Oracle10g,Oracle Sqldeveloper,Stored Functions,我有一个程序来更新从开始日期到结束日期的余额,以及 此外,我还想记录插入的记录数。我使用dbms_output.put_行获取插入的记录数,但它不提供任何输出,当执行完成时,将显示计数的输出。程序守则如下: create or replace function updatebal(start_date IN DATE, end_date IN DATE) RETURN NUMBER IS difference number; curr_r number; BEGIN difference
create or replace function updatebal(start_date IN DATE, end_date IN DATE)
RETURN NUMBER
IS
difference number;
curr_r number;
BEGIN
difference := end_date - start_date;
curr_r := 0;
while curr_r <= difference LOOP
curr_r := curr_r + 10;
for curr_in in 1..10 LOOP
date_value := date_value +1 ;
insertAvailBal(date_value);
commit;
select count(*) into totalCount from avail_bal;
dbms_output.put_line('total count' || totalCount);
end loop;
END LOOP;
RETURN 1;
END;
现在,我试图打印此过程中的totalCount,以获取插入此表avail_bal中的行数。但是没有产出。
请帮助我,提前感谢这就是dbms_输出的工作原理,它在运行完成后显示所有输出,您无法实时监控它 如果确实需要实时监控进度,可以使用具有自治事务的过程将消息插入到特殊表中,然后在另一个会话中,您可以在进程仍在运行时查看该表的内容 此类程序的示例:
procedure log_message (p_message varchar2) is
pragma autonomous_transaction;
begin
insert into message_table (message) values (p_message);
commit;
end;
dbms_输出就是这样工作的,它在运行完成后显示所有输出,您无法实时监视它 如果确实需要实时监控进度,可以使用具有自治事务的过程将消息插入到特殊表中,然后在另一个会话中,您可以在进程仍在运行时查看该表的内容 此类程序的示例:
procedure log_message (p_message varchar2) is
pragma autonomous_transaction;
begin
insert into message_table (message) values (p_message);
commit;
end;
正如Tony已经回答的那样:您不能改变dbms_输出的行为 向存储过程外部发送进度信号的推荐方法是使用dbms_应用程序_信息包来管理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;
/
有关更多详细信息,请参阅手册:
正如Tony已经回答的那样:您不能更改dbms\u输出的行为 向存储过程外部发送进度信号的推荐方法是使用dbms_应用程序_信息包来管理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;
/
有关更多详细信息,请参阅手册: