I use the log table instead of dbms_output. Remember to set up an offline transaction, something like (for your needs, of course):
create or replace package body somePackage as ... procedure ins_log( i_msg in varchar2, i_msg_type in varchar2, i_msg_code in number default 0, i_msg_context in varchar2 default null ) IS PRAGMA AUTONOMOUS_TRANSACTION; begin insert into myLogTable ( created_date, msg, msg_type, msg_code, msg_context ) values ( sysdate, i_msg, i_msg_type, i_msg_code, i_msg_context ); commit; end ins_log; ... end;
Be sure to create your own log table. In your code, if you perform many operations in a loop, you may want to register only once per operation x num, for example:
create or replace myProcedure as cursor some_cursor is select * from someTable; v_ctr pls_integer := 0; begin for rec in some_cursor loop v_ctr := v_ctr + 1; -- do something interesting if (mod(v_ctr, 1000) = 0) then somePackage.ins_log('Inserted ' || v_ctr || ' records', 'Log', i_msg_context=>'myProcedure'); end if; end loop; commit; exception when others then somePackage.ins_log(SQLERRM, 'Err', i_msg_context=>'myProcedure'); rollback; raise; end;
Note that a stand-alone transaction ensures that your stmt log will be inserted even if an error occurs and you roll back everything else (starting with a single transaction).
Hope this helps ... much better than dbms_output;)
tbone
source share