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