Home » Fusion Middleware & Colab Suite » Weblogic & Application Server » save dynamic HTML to file using UTL_FILE
save dynamic HTML to file using UTL_FILE [message #77172] Tue, 12 October 2004 12:19 Go to next message
Chuck
Messages: 9
Registered: January 2002
Junior Member
I have a stored procedure which creates a web page, but instead of sending it to the browser, I want to store the HTML as a file using UTL_FILE.

I have been successful with the following code, but can only capture the first 32k of the page this way. My pages are much larger!
How can I capture the ENTIRE DOCUMENT?!

My code (with all credit going to askTom.oracle.com) -
The following procedure is called immediately after the page-creating procedure:

create or replace procedure dump_page( p_dir in varchar2,
p_fname in varchar2 )
is
l_thePage htp.htbuf_arr;
l_output utl_file.file_type;
l_lines number default 99999999;
begin
l_output := utl_file.fopen( p_dir, p_fname, 'w' );

owa.get_page( l_thePage, l_lines );

for i in 1 .. l_lines loop
utl_file.put( l_output, l_thePage(i) );
end loop;

utl_file.fclose( l_output );
end dump_page;
/
Re: save dynamic HTML to file using UTL_FILE [message #77173 is a reply to message #77172] Tue, 12 October 2004 14:39 Go to previous message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
You need to join the pieces in each array element together, then write chunks to file. Try this:

CREATE OR REPLACE PROCEDURE dump_page (p_dir IN VARCHAR2, p_fname IN VARCHAR2)
IS
   l_thepage   HTP.htbuf_arr;
   l_output    UTL_FILE.file_type;
   l_lines     NUMBER             DEFAULT 99999999;
   l_piece1    VARCHAR2 (255);
   l_piece2    VARCHAR2 (255);
BEGIN
   l_output    := UTL_FILE.fopen (p_dir, p_fname, 'w');
   OWA.get_page (l_thepage, l_lines);

   FOR i IN 1 .. l_lines
   LOOP
      l_piece1    := NULL;
      l_piece2    := NULL;

      IF INSTR (l_thepage (i), CHR (10)) > 0
      THEN
         l_piece1    := SUBSTR (l_thepage (i), 1, INSTR (l_thepage (i), CHR (10)) - 1);
         l_piece2    := SUBSTR (l_thepage (i), INSTR (l_thepage (i), CHR (10)));
         UTL_FILE.put_line (l_output, l_piece1);
         UTL_FILE.put (l_output, l_piece2);
      ELSE
         UTL_FILE.put (l_output, l_thepage (i));
      END IF;
   END LOOP;

   UTL_FILE.fclose (l_output);
END dump_page;
/
Previous Topic: 2 (or More) Applications on a SINGLE App Server?
Next Topic: Problems with calling Reports from Forms
Goto Forum:
  


Current Time: Sun Sep 27 22:01:19 CDT 2020