ORU-10027: buffer overflow, limit of 100000 bytes - sql

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.

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.

reading and writing text files using UTL_FILE package remotely

I 'am trying to read and write files using utl_file package remotely but the oracle server cant read and write on other pc ,so i make a shared path on '\\adel-pc\test', and i want to read and write on that path but i get this error when reading :
SQL Error [29283] [99999]: ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at line 8
java.sql.SQLException: ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at line 8
and this error when writing :
SQL Error [29283] [99999]: ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at line 7
java.sql.SQLException: ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at line 7
and this is my code :
CREATE OR REPLACE DIRECTORY utl_test AS '\\10.10.60.11\test';
-- reading the file
DECLARE
p_dir varchar2(2000):='UTL_TEST';
p_file_name varchar2(2000):='IFD18021801IFEEDTL'; --file name
l_file UTL_FILE.file_type;
l_text varchar2(32767);
begin
l_file := UTL_FILE.fopen(p_dir,p_file_name,'r');
LOOP
UTL_FILE.get_line(l_file,l_text);
DBMS_OUTPUT.put_line(l_text);
END LOOP;
UTL_FILE.fclose(l_file);
EXCEPTION
WHEN UTL_FILE.invalid_operation THEN dbms_output.PUT_LINE('cannot open file invalid name');
WHEN UTL_FILE.read_error THEN dbms_output.PUT_LINE('cannot be read');
WHEN no_data_found THEN dbms_output.PUT_LINE('end of file');
UTL_FILE.fclose(l_file);
END;
--writing the file
declare
l_file UTL_FILE.file_type;
l_location varchar2(100) := 'UTL_TEST'; -- capital latter
l_filename varchar2(100) := 'am';
begin
l_file := UTL_FILE.fopen(l_location,l_filename,'w');
FOR i IN (SELECT * FROM hr.EMPLOYEES)
LOOP
UTL_FILE.PUT_LINE(l_file,i.EMPLOYEE_ID||' '||i.FIRST_NAME);
END LOOP;
UTL_FILE.fclose(l_file);
l_file := UTL_FILE.fopen(l_location,l_filename,'A');
UTL_FILE.PUT_LINE(l_file,'Additonal lines');
UTL_FILE.fclose(l_file);
END;
so my questions are:
could I write and read on the shared path or it cant be done using utl_file ?
why I am getting this error , knowing that I gave read & write permissions to that path.
I'd suggest you not to do it that way.
First of all, you're creating that procedure in SYS schema, which is - generally speaking - a bad idea. Leave SYS (and SYSTEM) alone; create your own user, grant it required privileges (CREATE SESSION, CREATE PROCEDURE and any other you might require), connect to it and then write code you want.
Why are you creating directories dynamically? That is a one-time job and should be done once, connected as SYS. Although you might have created those directories (it is a good idea to first DBMS_OUTPUT.PUT_LINE command you're about to execute, make sure it is correctly written and then actually run it), you did not grant READ nor WRITE privileges on them to anyone, so - nobody can use them but SYS and - as I've said above - don't use SYS for that.
Note that I'm not talking about operating system privileges, but Oracle ones, e.g.
grant read, write on directory some_dir to scott;
Finally, as of creating a directory on a computer that is not the database server: you should use UNC (Universal Naming Convention) and create a directory literally as \\adel-pc\test; it won't work if you map that directory on the server and use its drive letter.
As of the error itself, huh ... you posted several hundreds lines of code, it is little bit too much to debug just by looking at it, and we miss other objects you use. No idea, sorry.
finally the problem is solved ,the problem was in windows system privileges , I had to give full control permissions to the files ,so yes i can write and read on the shared path using utl_file .

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

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;

Trying to read the file using utl_file method

I am trying to see if this file exists. But I'm getting this error message. I have already checked the privileges I got them. But this file is on the server side so is there something I am missing
DECLARE
vInHandle utl_file.file_type;
BEGIN
vInHandle := utl_file.fopen('IMG_UTL_DIR', 'image-file.csv', 'R');
IF utl_file.is_open(vInHandle) THEN
dbms_output.put_line('The File exists');
Else
dbms_output.put_line('The File not exists');
END IF;
END fopen;
Errors:
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at line 5
If the file does not exist then you will get that error. With your code, when the file exists you will get:
anonymous block completed
The File exists
But when the file does not exist you will get:
Error report -
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at line 6
29283. 00000 - "invalid file operation"
*Cause: An attempt was made to read from a file or directory that does
not exist, or file or directory access was denied by the
operating system.
*Action: Verify file and directory access privileges on the file system,
and if reading, verify that the file exists.
Note the 'a file or directory that does not exist' part of the error description. You cannot test for the file's existence like this. As far as I'm aware there is no direct way to test for a file being there; you would have to attempt to open the file and catch the exception. For example:
DECLARE
vInHandle utl_file.file_type;
eNoFile exception;
PRAGMA exception_init(eNoFile, -29283);
BEGIN
BEGIN
vInHandle := utl_file.fopen('IMG_UTL_DIR', 'image-file.csv', 'R');
dbms_output.put_line('The File exists');
EXCEPTION
WHEN eNoFile THEN
dbms_output.put_line('The File not exists');
END;
END fopen;
/
anonymous block completed
The File not exists
But the ORA-29283 exception can mean other things as well, as the description says, so it doesn't necessarily mean the file is not there - it could be there but not accessible for some other (permission-related) reason. You would also be masking the location of the actual error to some extent, and if you had multiple file operations in the block then you'd either have to wrap each one in its own begin/exception/end sub-block to specify the error, or lose the actual error point.
You're probably better off just letting the exception be raised and reported naturally, rather than catching it and replacing it with a dbms_output message which might not be retrieved and displayed by the client anyway.

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.