Sponsored

Dbms_Output.Put_Line is a good way to debug PLSQL code easily by getting print the required values to track where the things are going wrong. But if you want to log that print data into a table to analyze it any time, you can do this with Dbms_Output.Get_Lines procedure.
dbms_output.put_line output to table with dbms_output.get_lines
The example is given below to log Dbms_Output.Put_Line print values into a table in Oracle. Below is the structure of the table which is used in this example named "outputlog" or you can create your own as per your requirement.

CREATE TABLE OUTPUTLOG
(
  CHAR_COL  VARCHAR2(1000 BYTE),
  PROCNAME  VARCHAR2(100 BYTE),
  LOG_DATE  DATE
);

And the following is the PLSQL anonymous block example to log the output:

DECLARE
   n      NUMBER := 100;
   vcol   DBMS_OUTPUT.chararr;
BEGIN
   DBMS_OUTPUT.enable (100000);
   --- do something here
   DBMS_OUTPUT.put_line ('first line');
   --- do somthing here 
   DBMS_OUTPUT.put_line ('second line');
   --- do something here
   DBMS_OUTPUT.put_line ('third line');

   --- get the output into vcol array
   DBMS_OUTPUT.get_lines (vcol, n);

   FOR i IN 1 .. n
   LOOP
      INSERT INTO outputlog (char_col, procname, log_date)
          VALUES (vcol (i), 'anonymous', SYSDATE);
   END LOOP;

   COMMIT;
END;

Note I assing the value of 100 to n variable and the number of output lines are only 3 so it will loop and record only 3 times because it is having only 3 rows in output, but if the output buffer is having rows more than 100 than it will log only 100 rows, so adjust this variable value accordingly.

Oracle Forms Recipes eBookDownload

An example given for DBMS_OUTPUT.Get_Lines and DBMS_OUTPUT.Put_Line procedures in Oracle to log the output into a table.

Post a Comment

V. Kapoor

{picture#https://3.bp.blogspot.com/-q3wCssWUHo8/ViDFfCpPEuI/AAAAAAAAD0M/MHPvgnl3T3U/s1600/authpic.JPG} Vinish Kapoor is a Software Consultant, currently working in a reputed IT company in Noida, India and doing blogging on Oracle Forms, SQL and PLSQL topics. He is an author of an eBook Oracle Forms Recipes, which is available on Google play. {facebook#https://www.facebook.com/foxinfotech2014} {twitter#https://twitter.com/foxinfotech} {google#https://plus.google.com/u/0/+VKapoor/posts}
Fox Infotech. Powered by Blogger.