UsingDBMS_OUTPUT
意味着 SQL*Plus 在整个 PL/SQL 块完成之前什么都不显示,然后将显示当前缓冲区中的所有数据。因此,这不是提供持续状态的适当方式。
另一方面,Oracle 确实提供了一个包DBMS_APPLICATION_INFO,它专门用于帮助您监控正在运行的代码。例如,您可以执行类似的操作
CREATE PROCEDURE process_structures
AS
<<other variable declarations>>
rindex BINARY_INTEGER;
slno BINARY_INTEGER;
totalwork NUMBER := y; -- Total number of structures
worksofar NUMBER := 0; -- Number of structures processed
BEGIN
rindex := dbms_application_info.set_session_longops_nohint;
FOR i IN (<<select structures to process>>)
LOOP
worksofar := worksofar + 1;
dbms_application_info.set_session_longops(
rindex => rindex,
slno => slno,
op_name => 'Processing of Molecular Structures',
sofar => worksofar ,
totalwork => totalwork,
target_desc => 'Some description',
units => 'structures');
<<process your structure with your existing code>>
END LOOP;
END;
从单独的 SQL*Plus 会话中,您可以通过查询V$SESSION_LONGOPS
视图来监控进度
SELECT opname,
target_desc,
sofar,
totalwork,
units,
elapsed_seconds,
time_remaining
FROM v$session_longops
WHERE opname = 'Processing of Molecular Structures';