Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Writing CLOB out to a file

823919Oct 11 2011 — edited Oct 12 2011
Can someone tell me what I'm doing wrong in the code below. It creates an output file of size 8192 every time and just cuts off before completing the output. While stepping through the code I'm showing the size of the CLOB passed in is 13888 so I'm not sure what's going on.
PROCEDURE p_xmlout (pi_dir    IN VARCHAR2,
                       pi_file   IN VARCHAR2,
                       pi_clob   IN CLOB)
   AS
      l_output   UTL_FILE.file_type;
      l_amt      NUMBER DEFAULT 32000;
      l_pos      NUMBER DEFAULT 1;
      l_length   NUMBER DEFAULT NVL(DBMS_LOB.getlength (pi_clob), 0);
   BEGIN
      IF l_length < 32760
      THEN
         l_output :=
            UTL_FILE.fopen (pi_dir,
                            pi_file,
                            'w',
                            32767);
         UTL_FILE.put (l_output, DBMS_LOB.SUBSTR (pi_clob, 32767, 1));
         UTL_FILE.fflush (l_output);
         UTL_FILE.fclose (l_output);
      ELSE
         l_output :=
            UTL_FILE.fopen (pi_dir,
                            pi_file,
                            'w',
                            32767);

         WHILE (l_pos < l_length)
         LOOP
            UTL_FILE.put (l_output, DBMS_LOB.SUBSTR (pi_clob, l_amt, l_pos));
            UTL_FILE.fflush (l_output);
            l_pos := l_pos + l_amt;
         END LOOP;

         UTL_FILE.new_line (l_output);
         UTL_FILE.fclose (l_output);
      END IF;
   END p_xmlout;
Edited by: 820916 on Oct 11, 2011 2:26 PM

Edited by: 820916 on Oct 11, 2011 2:27 PM

Edited by: 820916 on Oct 11, 2011 2:28 PM

Edited by: 820916 on Oct 11, 2011 2:29 PM
This post has been answered by BluShadow on Oct 12 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 9 2011
Added on Oct 11 2011
4 comments
739 views