Apex

Download Txt File from oracle database using Apex PL-SQL process

En este post , nosotros veremos como descargar archivos txt o cualquiera desde un proceso de  Apex Oracle.

En el ejemplo retornaremos el primer archivo de la tabla.

Adicionalmente crearemos este proceso en el before header y sera llamado con un submit desde la misma pagina.

Puede ver la demo aqui demo here   user: demo/ pass: demo

Dejo algunos enlaces fuente original del post, solo que aqui tengo el codigo mas simple posible para la ejecucion de este proceso.

Link1
Link2
Link3

Paso1: Crear un proceso After Header

declare 
    l_xml clob; 
    l_blob blob; 
    l_lang_context integer := DBMS_LOB.DEFAULT_LANG_CTX; 
    l_warning integer := DBMS_LOB.WARN_INCONVERTIBLE_CHAR; 
    l_dest_offset integer := 1; 
    l_source_offset integer := 1; 
    l_name varchar2(250);
begin
    dbms_lob.createtemporary(l_blob, true); 
begin 
    Select FILE_BLOB,FILENAME 
      into l_blob,l_name 
      from BLOG_FILES 
     where rownum = 1;
    exception when others then RETURN; 
    --apex_application.stop_apex_engine; 
    --owa_util.http_header_close; 
end; 
    /*if l_blob is null then return; end if;*/ 
    
    htp.init;
    -- Set the MIME typebranck
    owa_util.mime_header( \'application/octet-stream\', FALSE,\'UTF-8\' );
    -- Set the name of the file 
    htp.p(\'Content-Disposition: attachment; filename=\"\'||l_name||\'\"\');
    owa_util.http_header_close; 
    --package that provides an interface to download files (BLOBs and BFILEs)
    wpg_docload.download_file( l_blob ); 
    --stop further processing and immediately exit
    apex_application.stop_apex_engine; 
    exception when others then
    htp.prn(\'error: \'||sqlerrm); 
    apex_application.stop_apex_engine; 
end; 

Paso 2 crear un boton en la misma pagina con un submit y un request \”DOWNLOAD\” el mismo que sera usado como server side condition por el proceso afterHeader.

4 thoughts on “Download Txt File from oracle database using Apex PL-SQL process

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s