Oracle APEX - An unexpected error with the following message occurred: application/pdf - sql

I have a pl/sql procedure that that downloads a blob file in pdf format from Jasper Server. In this procedure I have the following code which prompts the browser to download the file to my local drive.
begin
v_param_val (1) := 1;
owa.init_cgi_env (v_param_val);
htp.flush;
-- clear the output buffer and reset response state
htp.init;
owa_util.mime_header ('application/pdf', false);--,'UTF-8'
htp.p('Content-length: ' || v_lob_length);
htp.p('Content-Disposition: attachement; filename="'||v_file||'"' );
owa_util.http_header_close;
htp.showpage ();
wpg_docload.download_file(v_blobref);
exception
when timeout_on_resource then
raise_application_error (-00051,'No response from the server.');
when others then
htp.p('other error : ' || sqlerrm);
end;
The problem is, I have an oracle apex page that I use to call my procedure. The page passes through the values to be used as parameters in the call of the procedure. I have a an apex process that makes this happen...
declare
v_report_name reports_data.report_name%type;
begin
v_report_name := s_reports_data.get_report_name(:P31_AVAILABLE_REPORTS);
s_reports_data.generate_jasper_report(v_report_name, :P31_DATE_TO,
:P31_RESEARCH_STATION, :P31_DATE_FROM);
end;
No the following error comes up when I try to call the procedure.
An unexpected error with the following message occurred: application/pdf
It seems like the following line is the cause of the error.
owa_util.mime_header ('application/pdf', false);--,'UTF-8'
Or the following line.
wpg_docload.download_file(v_blobref);

Looking in the docs, the function seems to need 3 parameters. Have you tried
owa_util.mime_header('application/pdf', false, 'UTF-8')

I finally got rid of the problem I had. This is how my code looks like now and it works perfectly fine.
begin
sys.htp.init;
sys.owa_util.mime_header (nvl(v_mime,'application/octet'), false, 'UTF-8');
sys.htp.p('Content-length: ' || v_lob_length);
sys.htp.p('Content-Disposition: attachement; filename="'||v_file||'"' );
sys.owa_util.http_header_close;
sys.wpg_docload.download_file(v_blobref);
apex_application.stop_apex_engine;
exception when others then
sys.htp.prn('error: '||sqlerrm);
apex_application.stop_apex_engine;
end;

Related

ORA-20000: ORU-10027: buffer overflow, limit of 1000000 bytes [duplicate]

I am getting below error while generating 100k record in PL/SQL. I have created a package and calling that package from anonymous block.
Error report -
ORA-20000: ORU-10027: buffer overflow, limit of 100000 bytes
ORA-06512: at "SYS.DBMS_OUTPUT", line 32
ORA-06512: at "SYS.DBMS_OUTPUT", line 97
ORA-06512: at "SYS.DBMS_OUTPUT", line 112
ORA-06512: at "APPS.PJM_ECC_DATA_POPULATION", line 126
ORA-06512: at line 13
20000. 00000 - "%s"
*Cause: The stored procedure 'raise_application_error'
was called which causes this error to be generated.
I am using below line to print log
dbms_output.put_line('After pjm_project_params_pkg.insert_row: Row ID: ' || l_rowid);
I have read some of the answers and they have suggested to use below.
DBMS_OUTPUT.ENABLE(1000000)
I dont know where in package I should put the same? will it solve the problem?
I put below in my anonymous block but it dit not help
set serveroutput on size 1000000
If at all logging to a server side file is an option,then UTL_FILE is the best bet.It doesn't complain about buffer overflow.
DECLARE
v_MyFileHandle UTL_FILE.FILE_TYPE;
BEGIN
--Change the folder based on host operating System
v_MyFileHandle := UTL_FILE.FOPEN('C:\','LOG.TXT','a');
FOR i in 1..1000000
LOOP
UTL_FILE.PUT_LINE(v_MyFileHandle, ' Record written to file at ' || TO_CHAR(SYSDATE,'MM-DD-YY HH:MI:SS AM')||' is '||i);
END LOOP;
UTL_FILE.FCLOSE(v_MyFileHandle);
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE
('ERROR ' || TO_CHAR(SQLCODE) || SQLERRM);
END;
You can open the file in read-only mode and can see the progress as the records are written while the script is running.This is a bonus.
For more details worth reading oracle documentation : https://docs.oracle.com/database/121/ARPLS/u_file.htm#ARPLS72681
If you're blowing the limits of DBMS_OUTPUT you should probably use a logging table to record your trace messages.
Being an Oracle built-in library, DBMS_OUTPUT has the advantage of availability. That is its only advantage. Its output is hard to search, a problem which is logarithmic to the size of output. It is not persistent. It is troublesome to manage in other environments.
Unfortunately Oracle does not provide a PL/SQL logger utility but you don't have to write your own (unless you want to). Use Tyler Muth's third-party library. It is the closest thing we have to an industry standard. Find it on GitHub.
i did face the same error
ORA-20000: ORU-10027: buffer overflow, limit of 100000 bytes
cause i am updating the ~91k records and due to one condition error
mine else part is only executing where i defined this error code
V_CODE := SQLCODE;
V_ERRM := SUBSTR(SQLERRM, 1, 100);
DBMS_OUTPUT.PUT_LINE(' Error code ' || V_CODE || ': ' || V_ERRM );
V_ERR_CNT := V_ERR_CNT + 1;
to resolve this issue , i put it as below
ALTER SESSION SET DB_FILE_MULTIBLOCK_READ_COUNT=128;
ALTER SESSION SET SORT_AREA_SIZE=500000000;
ALTER SESSION SET SORT_AREA_RETAINED_SIZE=500000000;
set serveroutput on size unlimited
and i also resolved the If condition part as in the result set i am only printing the count.

ORU-10027: buffer overflow, limit of 100000 bytes

I am getting below error while generating 100k record in PL/SQL. I have created a package and calling that package from anonymous block.
Error report -
ORA-20000: ORU-10027: buffer overflow, limit of 100000 bytes
ORA-06512: at "SYS.DBMS_OUTPUT", line 32
ORA-06512: at "SYS.DBMS_OUTPUT", line 97
ORA-06512: at "SYS.DBMS_OUTPUT", line 112
ORA-06512: at "APPS.PJM_ECC_DATA_POPULATION", line 126
ORA-06512: at line 13
20000. 00000 - "%s"
*Cause: The stored procedure 'raise_application_error'
was called which causes this error to be generated.
I am using below line to print log
dbms_output.put_line('After pjm_project_params_pkg.insert_row: Row ID: ' || l_rowid);
I have read some of the answers and they have suggested to use below.
DBMS_OUTPUT.ENABLE(1000000)
I dont know where in package I should put the same? will it solve the problem?
I put below in my anonymous block but it dit not help
set serveroutput on size 1000000
If at all logging to a server side file is an option,then UTL_FILE is the best bet.It doesn't complain about buffer overflow.
DECLARE
v_MyFileHandle UTL_FILE.FILE_TYPE;
BEGIN
--Change the folder based on host operating System
v_MyFileHandle := UTL_FILE.FOPEN('C:\','LOG.TXT','a');
FOR i in 1..1000000
LOOP
UTL_FILE.PUT_LINE(v_MyFileHandle, ' Record written to file at ' || TO_CHAR(SYSDATE,'MM-DD-YY HH:MI:SS AM')||' is '||i);
END LOOP;
UTL_FILE.FCLOSE(v_MyFileHandle);
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE
('ERROR ' || TO_CHAR(SQLCODE) || SQLERRM);
END;
You can open the file in read-only mode and can see the progress as the records are written while the script is running.This is a bonus.
For more details worth reading oracle documentation : https://docs.oracle.com/database/121/ARPLS/u_file.htm#ARPLS72681
If you're blowing the limits of DBMS_OUTPUT you should probably use a logging table to record your trace messages.
Being an Oracle built-in library, DBMS_OUTPUT has the advantage of availability. That is its only advantage. Its output is hard to search, a problem which is logarithmic to the size of output. It is not persistent. It is troublesome to manage in other environments.
Unfortunately Oracle does not provide a PL/SQL logger utility but you don't have to write your own (unless you want to). Use Tyler Muth's third-party library. It is the closest thing we have to an industry standard. Find it on GitHub.
i did face the same error
ORA-20000: ORU-10027: buffer overflow, limit of 100000 bytes
cause i am updating the ~91k records and due to one condition error
mine else part is only executing where i defined this error code
V_CODE := SQLCODE;
V_ERRM := SUBSTR(SQLERRM, 1, 100);
DBMS_OUTPUT.PUT_LINE(' Error code ' || V_CODE || ': ' || V_ERRM );
V_ERR_CNT := V_ERR_CNT + 1;
to resolve this issue , i put it as below
ALTER SESSION SET DB_FILE_MULTIBLOCK_READ_COUNT=128;
ALTER SESSION SET SORT_AREA_SIZE=500000000;
ALTER SESSION SET SORT_AREA_RETAINED_SIZE=500000000;
set serveroutput on size unlimited
and i also resolved the If condition part as in the result set i am only printing the count.

Oracle Apex 4.2 custom file download error 404 Not Found or 403 Forbidden

I'am using Oracle Apex and I have a form to upload and store a file in a table via wwv_flow_files
In order to download the file I am using the procedure download_my_file
When I try to click the link and download the error 404 is raised
My environment is
Application Express 4.2.6.00.03
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
Oracle Rest Data Service 3.0.9.348.07.16
Thanks to any suggestion or advice
EDIT:
I check the stored procedure in Apex going Home->SQL Workshop->SQL Commands
If I copy and paste the code and instead of the parameter I use a known ID the execution is successful.
With the syntax download_my_file?p_file=#ID# url is
http://myhost:8080/ords/download_my_file?p_file=24255
the error 404 Not found is raised.
With the syntax #OWNER#.download_my_file?p_file=#ID# url is
http://myhost:8080/ords/mypdb.download_my_file?p_file=24255
the error 403 Forbidden is raised.
EDIT 2 : as requested here is the procedure
PROCEDURE download_my_file(p_file in number) AS
v_mime VARCHAR2(48);
v_length NUMBER;
v_file_name VARCHAR2(2000);
Lob_loc BLOB;
BEGIN
SELECT files_mime_type, files_content, files_name, dbms_lob.getlength(files_content)
INTO v_mime,lob_loc,v_file_name,v_length
FROM pub_db0files
WHERE files_id = p_file;
--
-- 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( nvl(v_mime,'application/octet'), FALSE );
-- 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="'||replace(replace(substr(v_file_name,instr(v_file_name,'/')+1),chr(10),null),chr(13),null)|| '"');
-- close the headers
owa_util.http_header_close;
-- download the BLOB
wpg_docload.download_file( Lob_loc );
end download_my_file;
According to documentation «Fusion Middleware User's Guide for mod_plsql» regarding to wpg_docload.download_file we have to «add the line WindowsFileConversion Off to DAD entry.
Open the file ORACLE_INSTANCE\config\OHS\ohs1\mod_plsql\dads.conf.
Locate the DAD used to access the application.
Add the line WindowsFileConversion Off to this DAD entry.
Save the file.
Restart Oracle HTTP Server.
If you do not update the DAD configuration, you will experience failures while downloading documents which contain 0x5c in the filename. For example:
In Oracle Portal, you will see the download error:
Error: Document not found (WWC-46000)
When using mod_plsql against your own PL/SQL application, file downloads will result in the error:
HTTP-404 Not Found
https://docs.oracle.com/cd/E28280_01/portal.1111/e12041/concept.htm#YPMOD001

Throwing error while printing record element string?

Throwing error while printing record element string using put why please help me to understand?
with ada.text_io;
use ada.text_io;
procedure main is
type my_rec is record
name:string(1..5)of integer;
end record;
var:my_rec;
begin
var.name:="hello";
put(var.name); -- why error?
end main;
error message is below
cc -c hello.adb
hello.adb:7:27: missing ";"
gnatmake: "main.adb" compilation error
hello.adb:7:27 is the coordinates of the error, so take a look in "hello.adb" on line 7 at character position 27.

Cancel SQL *PLUS Execution without raising an error

i have a tricky SQL Problem:
We have a huge SQL Script which installs our application on the DB server.
We want to skip the database installation if the latest update didn't change anything in the DB.
I have implemented following check, which is executed before the other SQL commands:
check_current_version_delta.sql:
DECLARE
v_deploy_version VARCHAR2(30) := '&db_deploy_version';
v_check BOOLEAN := FALSE;
BEGIN
DBMS_OUTPUT.PUT_LINE( '--------------------------------------------------------------------------------');
DBMS_OUTPUT.PUT_LINE( 'Check if we have a new DB version');
DBMS_OUTPUT.PUT_LINE( '--------------------------------------------------------------------------------');
FOR cu_version IN (SELECT version FROM &DB_CURRENT_USER..db_deployment WHERE version = v_deploy_version AND ROWNUM = 1) LOOP
v_check := TRUE;
END LOOP;
IF v_check THEN
RAISE_APPLICATION_ERROR( -20001, 'DB Version: '||v_deploy_version||' is already installed');
END IF;
END;
/
This is working very well but our installation team complains about the ORA-XXXXX Error in the log, because they have automated error checks this installation is marked as FAIL (though there was no actual error)
So now the actual problem:
I need to cancel the execution of the SQL without any errors in the LOG. Is this even possible?
Alternative would be to make the rest of the installation dependent on the outcome of the script above. But i'm not sure how to accomplish that.
Have you some suggestions on how to handle it the good way?
One possible way is to create three scripts: The first checks for the condition and either calls the second or the third. The second does the real job. The third is an empty dummy, to avoid the error message cause by calling a non-existent script
In code, it looks like this:
col SCRIPT1_COL new_val SCRIPT1
SELECT case
when version = '&db_deploy_version' then 'dummy.sql'
else 'upgrade_db.sql'
end as SCRIPT1_COL
FROM &DB_CURRENT_USER..db_deployment;
#&SCRIPT1
Alternatively, you could use the method shown above to load either a script "dummy.sql" that does nothing or a script "exit.sql" that just contains the exit command, and execute it before doing the real job.
Presumably you're already using whenever sqlerror so make it terminate when you raise that exception, and you're redirecting the output to your log file. If so you can just hide the text of the exception with set termout off:
whenever sqlerror exit success
set termout off
DECLARE
...
BEGIN
...
IF v_check THEN
RAISE_APPLICATION_ERROR( -20001,
'DB Version: '||v_deploy_version||' is already installed');
END IF;
END;
/
set termout on
whenever sqlerror exit failure
... the rest of your script
The script will stop if the exception is raised but produce no output. The success means anything that runs this won't decide it has errored independently of the log; the exit code from sqlplus will be zero.
You may be spooling to output instead; in which case just don't start the spool until after your check. Or if you have things before this that you do have to spool, turn the spool off and then on again afterwards with append.