Skip to Main Content

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, lisa.

Asked: July 03, 2001 - 10:19 am UTC

Last updated: May 25, 2011 - 11:31 am UTC

Version: oracle 7.3.4

Viewed 50K+ times! This question is

You Asked

I run a script from NT using plus80.exe, in this script it combines several steps including procedures, sqls. After it run about 7-8 min
I got this error ORA-20000 ORU-10027 buffer overflow, limit of 1000000 bytes, and then the step aborted.
Could you explain what is this overflow, and how to correct ?



and Tom said...

You are generating more then 1,000,000 characters of output via dbms_output.put_line calls. That is the maximum.

You can:

set serveroutput off

and then run your scripts but you will not get any dbms_output output. There is no way to up this limit.

See
</code> http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:146412348066 <code>
for a different implementation of dbms_output that doesn't have this limit.

followup to comment

grep your scripts for "serveroutput" and check your code for dbms_output.enable.

Someone must be turning it back on on you.


Rating

  (21 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Problem with buffer overflow

A reader, July 03, 2001 - 2:39 pm UTC

Very useful info.
But after I "set the serveroutput off" at the beginning, the error still there. Then I tried to
go into the code to physically remove the sys.dbms_output.PUT_LINE statements then I have a complete run.
Does this make sense to you ?

Lisa

line length Overflow

Rahul, July 24, 2002 - 2:15 am UTC

Hi Tom

BEGIN SP_COPYAUDITDATA_V1; END;

*
ERROR at line 1:
ORA-20000: ORU-10028: line length overflow, limit of 255 bytes per line
ORA-06512: at "SYS.DBMS_OUTPUT", line 99
ORA-06512: at "SYS.DBMS_OUTPUT", line 65
ORA-06512: at "FPIMLVER103.SP_COPYAUDITDATA_V1", line 112
ORA-06512: at line 1

this error is coming when I try to print something in variable but value is vaey large...
how can we overcome from this prob ?


ORU-10027,

Arabinda, December 07, 2002 - 8:57 am UTC

This is a very useful info.I am getting this error on our application.Recently this has started coming.By running the appl. (in Forms 6i) we are not setting serveroutput.The packages have dbms_output to print debugging information.I am running my application in Forms6i,and after some time I start getting the problem.I close the session and start another ,after some time this repeats.If I run a big process , it comes immediately.Does it mean,inside all the procedures/triggers code some where dbms_output.enable is there and creating the trouble?

Tom Kyte
December 07, 2002 - 10:23 am UTC

yes, someone has a dbms_output.enable in there somewhere.

Turn on SQL_TRACE and trace a session -- you might find it there.

Any other possibilities?

Basil, February 21, 2005 - 9:00 pm UTC

I'm running 9.2.0.4 on Linux (RHAS 3). I've got a PL/SQL code base that runs fine under Windows 2000. It's mostly batch stuff. However, on this new Linux installation, I'm getting buffer overflows (ORA-20000, etc.) from DBMS_OUTPUT when the code is run AS A JOB (total background process). I've grepped away, and I can find no instance of dbms_output.enable anywhere in the code. Is there anything else that turns this stuff on?

Tom Kyte
February 22, 2005 - 8:16 am UTC

there must be a dbms_output.enable - else this would not happen. something is turning it on.

as an Oracle job? or as a "cron job"

total background process to me means "snp0" or "j001" as in totally an oracle background process. and job means dbms_job. I've a feeling that you mean "we have a sqlplus script we run in the background and it is our "JOB"


If this is not "dbms_job", then someone has put "set server output on" in

a) a login.sql in the current working directory of your "job"
b) a login.sql in the $SQLPATH path
c) the glogin.sql file ($OH/sqlplus/admin)

so, check those out (and if you are running a sqlplus script, you could always just "set serveroutput OFF" in your script to undo whatever a login.sql did)

REAL Job

Basil, March 01, 2005 - 9:03 am UTC

Nope. The code in question is an AQ listener running in a job submitted by DBMS_JOB.SUBMIT. Everything is in the background.
According to grep, there is not a single call to DBMS_OUTPUT.ENABLE anywhere. SQL*Plus does not enter the picture at all.

Tom Kyte
March 01, 2005 - 9:17 am UTC

and if you stuff a dbms_output.disable at the beginning of the job while trying to diagnose this, does that in fact get you over the hurdle? (because if that does not, well -- somewhere in your code, there has to be an enable)

I tried the dbms_output.disable

Basil, March 01, 2005 - 9:37 am UTC

I added dbms_output.disable, to no effect.

Tom Kyte
March 01, 2005 - 9:55 am UTC

the *only* way I know for it to happen is when it is enabled, sorry -- don't know what else to say....


if you are willing to try (caution, I would do this in test first -- it will invalidate code, you'll want to review the side effects -- do NOT drop this into a running production system)

In YOUR SCHEMA (not sys -- YOUR schema only!!!) install this dummy package:

create or replace package dbms_output as

procedure enable (buffer_size in integer default 20000);
procedure disable;
procedure put(a varchar2);
procedure put(a number);
procedure put_line(a varchar2);
procedure put_line(a number);
procedure new_line;
procedure get_line(line out varchar2, status out integer);
procedure get_lines(lines out sys.dbms_output.chararr, numlines in out integer);
end;
/

create or replace package body dbms_output
as
procedure enable (buffer_size in integer default 20000)
is
begin
raise_application_error( -20001, 'I was called, the stack is found in the alert log' );
end;

procedure disable is begin sys.dbms_output.disable; end;
procedure put(a varchar2) is begin sys.dbms_output.put(a); end;
procedure put(a number) is begin sys.dbms_output.put(a); end;
procedure put_line(a varchar2) is begin sys.dbms_output.put_line(a); end;
procedure put_line(a number) is begin sys.dbms_output.put_line(a); end;
procedure new_line is begin sys.dbms_output.new_line; end;
procedure get_line(line out varchar2, status out integer) is begin sys.dbms_output.get_line(line,status); end;
procedure get_lines(lines out sys.dbms_output.chararr, numlines in out integer) is begin sys.dbms_output.get_lines(lines,numlines); end;
end;
/


Now, if someone is calling dbms_output.enable -- they'll call yours and you'll see it.

OR-20000

Ajay, March 01, 2005 - 11:12 am UTC

Basil,
If you're getting ORA-20000, maybe you should grep for raise_application_error.

Tom Kyte
March 01, 2005 - 11:30 am UTC

you won't find it that way, dbms_output raises an ora-20000

ops$tkyte@ORA9IR2> set serveroutput on size 2000
ops$tkyte@ORA9IR2> begin
  2  loop dbms_output.put_line( 'x' );
  3  end loop;
  4  end;
  5  /
x
x
x
...
x
x
begin
*
ERROR at line 1:<b>
ORA-20000: ORU-10027: buffer overflow, limit of 2000 bytes</b>
ORA-06512: at "SYS.DBMS_OUTPUT", line 35
ORA-06512: at "SYS.DBMS_OUTPUT", line 198
ORA-06512: at "SYS.DBMS_OUTPUT", line 139
ORA-06512: at line 2


 

DBMS_OUTPUT.PUT_line

mohini, September 01, 2005 - 10:35 pm UTC

Database Version: 9i (Release 2)

Tom,

How much performance hit is it to leave DBMS_OUTPUT statements
in in the production code...(assuming serveroutput is in off setting)
specially, if the dbms_output is embedded in lots of loops..

Thanks.


Tom Kyte
September 02, 2005 - 1:26 am UTC

</code> http://asktom.oracle.com/~tkyte/runstats.html <code>

benchmark it!

(but also ask, what cost is it to take them out. What if Oracle took out

v$ tables
timed statistics
sql_trace
all events
all diagnostic stuff

would Oracle run

a) faster
b) slower

???


I say "B, obviously". It would definitely be "B".

Without the diagnostic stuff, we would never get it running fast in the first place and we'd never be able to figure out what went wrong when it does.

Leave the debug in your procedure code so you can turn it on when necessary.


Here is some of my old production C code:

sprintf( plsql_block, "%s%s%s%s", BLOCK1, BLOCK2, BLOCK3, BLOCK4 );
debugf(( ctx, "length of pl/sql block is %d bytes", strlen(plsql_block)))

start = get_hsecs(ctx);
debugf(( ctx, "Attempting to describe '%s'", objname ))

if ( oparse(&ctx->cda, plsql_block, -1, 0, 2 )) die(ctx,oerr_cda(ctx));
debugf(( ctx, "describe pl/sql block parsed..." ))

if ( obndrv( &ctx->cda, "ObjectName", -1, objname, strlen(objname)+2,
STRING_TYPE, -1, 0, 0, -1, -1) ) die(ctx,oerr_cda(ctx));
debugf(( ctx, "Bound 'ObjectName'" ))

if ( obndrv( &ctx->cda, "AllNames", -1, AllNames, sizeof(AllNames),
STRING_TYPE, -1, &AllNamesI,0,-1,-1) ) die(ctx,oerr_cda(ctx));
debugf(( ctx, "Bound 'AllNames'" ))

if ( obndrv( &ctx->cda, "HasDefault", -1, HasDefault, sizeof(HasDefault),
STRING_TYPE, -1, &HasDefaultI,0,-1,-1) ) die(ctx,oerr_cda(ctx));
debugf(( ctx, "Bound 'HasDefault'" ))

if ( obndrv( &ctx->cda, "CountOfTables", -1, CountOfTables,
sizeof(CountOfTables), STRING_TYPE, -1, &CountOfTablesI,
0, -1, -1) ) die(ctx,oerr_cda(ctx));
debugf(( ctx, "Bound 'CountOfTables'" ))

if ( obndrv( &ctx->cda, "TableNames", -1, TableNames, sizeof(TableNames),
STRING_TYPE, -1, &TableNamesI,0,-1,-1)) die(ctx,oerr_cda(ctx));
debugf(( ctx, "Bound 'TableNames'" ))

if ( obndrv( &ctx->cda, "qualifiedObj", -1, qualifiedObj,
sizeof(qualifiedObj), STRING_TYPE, -1, &qualifiedObjI,0,-1,-1))
die(ctx,oerr_cda(ctx));
debugf(( ctx, "Bound 'qualifiedObj'" ))

Every other line -- debug, it never let me down :)

dbms_output relevant outside of sqlplus

Vlado, October 19, 2005 - 11:05 am UTC

I thought that worrying about dbms_output limitations is only relevant when used in conjunction with sqlplus. But this thread seems to indicate otherwise...
So, if I have a stored procedure (sp) that calls dbms_output.put_line and this sp is called from an non-sqlplus client I can still receive an ORA-20000: ORU-10027 ?

Tom Kyte
October 19, 2005 - 12:34 pm UTC

absolutely - dbms_output is not limited to sqlplus, anything can make use of it and anything can get an exception from it.

Arivazhagan, December 17, 2005 - 2:17 pm UTC

As always Excellent.I get an error message . Search for that in AskTom. Get the fix. Job done.

When do people get to really Ask Tom?? I only get to see Tom's message stating the obvious ( Sorry . I have a large backlog right now)I have been waiting to ask a question for a long time now.



Tom Kyte
December 17, 2005 - 4:29 pm UTC

I report on how many questions I've taken over the last 4 weeks on the home page :)

It varies from a few to two hundred or more. Depends on my schedule...

very helpful info

prasanth, January 06, 2006 - 4:29 am UTC

As all ways Tom is great .. very much helpful info!!!

Error through Job

Bidyut Shah, August 02, 2006 - 10:27 am UTC

I have a scheduled job which calls procedure xyz. When I run this job manually I get error 'ORA-20000: ORU-10027: buffer overflow, limit of 1000000 bytes', but when the same job is triggered by the scheduler, then I do not get this error. What could be the reason.

Thanks in advance.

Tom Kyte
August 02, 2006 - 12:09 pm UTC

because when you call this job manually you are probably sitting in sqlplus and probably have issued:

SQL> set serveroutput on ......


enabling dbms_output - and the buffer overflows.  In the job queue, the dbms_output stuff is not enabled.


set serveroutput off

or

set serveroutout on size 1000000

or in 10gr2

set serveroutput on size UNLIMITED 

Error through job (contd)

Bidyut Shah, August 09, 2006 - 8:28 am UTC

I have set serveroutput off but still I get the error

Tom Kyte
August 09, 2006 - 10:51 am UTC

somebody is therefore setting it back on.

look for dbms_output.enable calls in the code.

Good

amdix, December 29, 2006 - 10:17 am UTC

very helpful

Error due to buffer overflow

Avishek, July 17, 2008 - 7:57 am UTC

Hi,
This is the first time I am writing to you. I have gone thorugh your comments regarding my issue, but could not find any help.
I am using Oracle 10g rel 2. I have a small pl/sql code that gives less than 3000 characters output. I have to have the serveroutput on and have dbms_output.enable to max. However, I am still getting the buffer overflow error.
Is there any way to get around this?
Tom Kyte
July 17, 2008 - 11:47 am UTC

got example?


Avishek, July 17, 2008 - 12:18 pm UTC

I will give you the original example (well, almost) and paste the error output as well:
--====================
DECLARE
x NUMBER := 0;
y VARCHAR2(30) := null;
cursor C_Primary is select table_name,count(1)
from USER_CONS_COLUMNS
where constraint_name like '%CRPU_CARAT%_PK'
group by table_name;
BEGIN
dbms_output.enable(1000000);
dbms_output.put_line('=== Test Case to check no of Primary Keys in CARAT tables ===');
open C_Primary;
loop
fetch C_Primary into varTabName,varNumObj;
dbms_output.put_line('=== No of Primary Keys: '||varNumObj||' in Table: '||varTabName||' ==

end loop;
dbms_output.put_line('EXPECTED RESULTS STATUS = PASSED');
close C_Primary;
EXCEPTION
when OTHERS then
dbms_output.put_line('Error: '||sqlerrm);
dbms_output.put_line('EXPECTED RESULTS STATUS = FAILED');
END;
/
--=============
Error Output to the above query:
--=============
DECLARE
*
ERROR at line 1:
ORA-20000: ORU-10027: buffer overflow, limit of 1000000 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 line 20
--==============
I hope this works for you.
Tom Kyte
July 17, 2008 - 12:27 pm UTC

..
EXCEPTION
  when OTHERS then
    dbms_output.put_line('Error: '||sqlerrm);
    dbms_output.put_line('EXPECTED RESULTS STATUS = FAILED');
END;
.....


fail, I will never understand this, I will never get this, I cannot fathom why people do this, I cannot even begin to imagine the "logic".

delete those lines of code, they are a bug in your code, just delete them and stay away from when others.



 open C_Primary;
  loop
    fetch C_Primary into varTabName,varNumObj;
    dbms_output.put_line('=== No of Primary Keys: '||varNumObj||' in Table: 
'||varTabName||' ==

  end loop;



that is called an infinite loop. You have no "exit when" conditions

suggestion: do not use explicit cursors if you don't have to - and you don't. Easier to code simply like this:


DECLARE
  cursor C_Primary is select table_name,count(1) cnt
 from USER_CONS_COLUMNS
 where constraint_name like '%CRPU_CARAT%_PK'
 group by table_name;
BEGIN
  dbms_output.enable(1000000);
  dbms_output.put_line('=== Test Case to che....===');
  for x in c_primary loop
    fetch C_Primary into varTabName,varNumObj;
    dbms_output.put_line('=== No of Primary Keys: '|| x.cnt ||
                         ' in Table: '|| x.table_name ||' ==' );
   end loop;
  dbms_output.put_line('EXPECTED RESULTS STATUS = PASSED');
END;
/

Issue understood

Avishek, July 17, 2008 - 1:23 pm UTC

Thanks for the prompt answer. I have my problem solved.
Understandings:
1. Include an "exit when" when using explicit cursor (ofcourse, omitted by mistake...)
2. Stay away from others exception wherever possible (to write a small test case, like mine, I had to)
3. No need to use explicit cursor if not required (Point noted)

Thanks again.
Tom Kyte
July 18, 2008 - 4:05 pm UTC

1) avoid infinite loops :) yes.

2) you did not have to, you never have to. never. not ever. Not even for a small test case (I cannot think of a single reason why being a test case would cause you to use when others)

Workaround for buffer overflow

Probal, February 13, 2011 - 3:07 am UTC

Hi Tom,
I was doing a loading of data from a flat file to an Oracle table using utl_file package.I was getting the ora-20000 error for buffer overflow.My database was 10gR2.By setting dbms_output.enable(null) I got rid of the problem.But I am wondering if there are any disadvantages in doing so.
Are set serveroutput on and setting dbms_output.enable(null) equivalent?
Tom Kyte
February 14, 2011 - 7:44 am UTC

just disabling (you should call dbms_output.disable) will work as well - and make your code a little more efficient if you don't need the debug output each time you run it.

Karan, May 25, 2011 - 6:08 am UTC

Dear Tom,

Suppose i user dbms_output in one of my procedures. Does the data still stay in the buffer after the procedure is executed ? And so if a lot of procedures are run, the maximum limit of 1 million will be breached sometime or the other right (assuming that the db is not bounced in between)?

Also can u please specify how to clear this buffer and if it is a good idea to clear the buffer at the start of each and every procedure where dbms_output is being used.

Regards,
Karan
Tom Kyte
May 25, 2011 - 11:31 am UTC

unless you use sqlplus (or some tool like it) and "set serveroutput on" OR you explicitly call "dbms_output.enable" from your application - the buffering does not happen, the calls are just going to the equivalent of "/dev/null"

So, it shouldn't be a problem.

ORU-10027 on a pooled JDBC connection.

Al Ricafort, December 21, 2013 - 6:29 am UTC

Hi Tom,

We are getting ORU-10027 on our installation using WebLogic. It happens mostly when we call this particular stored procedure that has a number of dbms_output.put_line for debug. Now there is nothing wrong with this stored procedure so I suspect that somewhere another stored procedure issued an explicit dbms_output.enable or it is done on a java code. And since the connection are pooled means the next one to use it will have its dbms_output enabled.

My question now is is there a way to identify which session has its dbms_output enabled? We want to know so that we can kill this session and force our middleware to create a new one. This is our temporary solution while we identify those offending codes.

Also, there has been suggestion to remove the dbms_output.put_line (those used for debugging) before placing them into production. I totally disagree with this because I believe that you must instrument your code as much as possible. What is your opinion on this?

Thanks.

ORU-10027 on a pooled JDBC connection.

Al Ricafort, December 21, 2013 - 7:12 am UTC

Hi Tom,

I just realized that there may be no way of knowing which session has a dbms_output enabled. It is because dbms_output is just a package and the call to 'enable' may be just setting some package variable which resides in the sessions PGA. And the V$ tables are probably not interested in recording any of these.

Correct me if I am wrong.

Thanks.


More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library