Hi Folks
I took some advise from a thread here on downloading a clob from my DB as a file for the end user. I have build out the following procedure that is on a DA and grabs the data and such:
Declare
V_CLOB clob;
l_blob blob;
v_lang_context integer := DBMS_LOB.DEFAULT_LANG_CTX;
v_warning integer := DBMS_LOB.WARN_INCONVERTIBLE_CHAR;
v_dest_offset integer := 1;
v_length number;
v_source_offset integer := 1;
s_file_name varchar2(2000);
l_dest_offset integer := 1;
l_source_offset integer := 1;
l_lang_context integer := DBMS_LOB.DEFAULT_LANG_CTX;
l_warning integer := DBMS_LOB.WARN_INCONVERTIBLE_CHAR;
begin
select config
into V_CLOB
from temp_session_clob
where apex_session = APEX_CUSTOM_AUTH.GET_SESSION_ID
and location_id= :P17_LOCATION_ID;
apex_debug.info('APEX_CUSTOM_AUTH.GET_SESSION_ID' || APEX_CUSTOM_AUTH.GET_SESSION_ID || ' Loc:' || :P17_LOCATION_ID);
s_file_name := :P17_DATA_TYPE || '_' || :P17_BIZ_DATE || :p17_LOCATION_CODE || '.txt';
apex_debug.info('s_file_name: ' || s_file_name);
DBMS_LOB.CREATETEMPORARY(l_blob, TRUE);
DBMS_LOB.CONVERTTOBLOB
(
dest_lob =>l_blob,
src_clob =>V_CLOB,
amount =>DBMS_LOB.LOBMAXSIZE,
dest_offset =>l_dest_offset,
src_offset =>l_source_offset,
blob_csid =>DBMS_LOB.DEFAULT_CSID,
lang_context=>l_lang_context,
warning =>l_warning
);
v_length := dbms_lob.getlength(l_blob);
--
-- set up HTTP header
--
-- use an NVL around the mime type and
-- if it is a null set it to application/octect
-- application/octect may launch a download window from windows
owa_util.mime_header('application/octet');
apex_debug.info('VL: ' || v_length);
-- set the size so the browser knows how much to download
htp.p('Content-length: ' || v_length);
-- the filename will be used by the browser if the users does a save as
htp.p('Content-Disposition: attachment; filename="' || s_file_name || '"');
-- close the headers
owa_util.http_header_close;
-- download the BLOB
wpg_docload.download_file( l_blob );
exception when others then
apex_debug.info(DBMS_UTILITY.FORMAT_ERROR_STACK || DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);
raise;
end;
When this executes I get an error in the dev console on the browser :
/download-document/5877278421978 500 (Server Error)
However in the debug output from APEX, I don't see any error messages nor any details as to what is erroring….Is there somewhere else i may find the details of the erorr, or does someone see an obvious mistake?
My V_Length varibale shows that it has the data so it is retrieveing it from the DB.
Thanks!