Tuesday, January 1, 2013

alternate to oracle dbms output



CREATE TABLE mylog_t
  (
    "TIMESTAMP" DATE NOT NULL ENABLE,
    "LOG_TEXT" VARCHAR2(500 BYTE)
  );

  CREATE or replace PROCEDURE mylog(a_log_text       mylog_t.log_text%TYPE)
   IS
      PRAGMA AUTONOMOUS_TRANSACTION;
   BEGIN
      INSERT INTO mylog_t (timestamp,log_text)VALUES (SYSTIMESTAMP,a_log_text);
      COMMIT;
   END mylog;



shamelessly copied from http://berxblog.blogspot.com/2009/01/pipelined-function-vs-dbmsoutput.html

create or replace
function dummy
return DBMS_DEBUG_VC2COLL
PIPELINED -- NOTE the pipelined keyword
is
begin
pipe row (to_char(sysdate, 'DD-MON-YYYY HH24:MI:SS' ));
dbms_lock.sleep(15);
pipe row (to_char(sysdate, 'DD-MON-YYYY HH24:MI:SS' ));
return;
end;
/
Make sure you set the arraysize of SQL*PLUS (or whatever) small enough, otherwise you will get a bunch of results at once, not when they occure.
set arraysize 1
select * from table(dummy());
gives
COLUMN_VALUE
--------------------
20-JAN-2009 14:24:17
and after 15 sec.
20-JAN-2009 14:24:32