@@ -397,5 +397,56 @@ create or replace package body ut_utils is
397397 end if;
398398 return l_result;
399399 end;
400+
401+ procedure save_dbms_output_to_cache is
402+ l_status number;
403+ l_line varchar2(32767);
404+ l_line_no integer := 1;
405+ l_lines ut_varchar2_rows := ut_varchar2_rows();
406+ c_lines_limit constant integer := 100;
407+ pragma autonomous_transaction;
408+
409+ procedure flush_lines is
410+ begin
411+ insert into ut_dbms_output_cache (seq_no,text)
412+ select rownum, column_value
413+ from table(l_lines);
414+ l_lines.delete;
415+ end;
416+ begin
417+ loop
418+ dbms_output.get_line(line => l_line, status => l_status);
419+ exit when l_status = 1;
420+ l_lines := l_lines multiset union all ut_utils.convert_collection(ut_utils.clob_to_table(l_line||chr(7),4000));
421+ if l_lines.count > c_lines_limit then
422+ flush_lines();
423+ end if;
424+ end loop;
425+ flush_lines();
426+ commit;
427+ end;
428+
429+ procedure read_cache_to_dbms_output is
430+ l_lines_data sys_refcursor;
431+ l_lines ut_varchar2_rows;
432+ c_lines_limit constant integer := 100;
433+ pragma autonomous_transaction;
434+ begin
435+ open l_lines_data for select text from ut_dbms_output_cache order by seq_no;
436+ loop
437+ fetch l_lines_data bulk collect into l_lines limit c_lines_limit;
438+ for i in 1 .. l_lines.count loop
439+ if substr(l_lines(i),-1) = chr(7) then
440+ dbms_output.put_line(rtrim(l_lines(i),chr(7)));
441+ else
442+ dbms_output.put(l_lines(i));
443+ end if;
444+ end loop;
445+ exit when l_lines_data%notfound;
446+ end loop;
447+ delete from ut_dbms_output_cache;
448+ commit;
449+ end;
450+
400451end ut_utils;
401452/
0 commit comments