Skip to Main Content
  • Questions
  • Use of dbms_output package as industry standard

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Tanmay.

Asked: May 24, 2012 - 2:47 am UTC

Last updated: May 27, 2012 - 12:36 pm UTC

Version: 11.2.0

Viewed 1000+ times

You Asked

Hi!

I use dbms_output built-in package for debugging messages whenever I write a package/procedure etc., so that I know WHICH PART of code is creating problem.
But in my organization, it is not appreciated on the production environment and on code maintenance tools.

So, I wanted to know if it is an industry practice to not to include dbms_output package in the code? And if it is so, then why?

In my opinion, if we let it remain there, we are enabling code maintenance by helping the bug-fixer (if required in future) to find the problematic part of code within hundreds/thousands of line of code.

Thanks for your help.
Greatly appreciated.

and Tom said...


https://forums.oracle.com/forums/thread.jspa?messageID=10354764#10354764

;) already asked and answered - including links to my thoughts on this.


They should have no problem with dbms_output in "production" code. The only time it is enabled by default is...

never.

You have to explicitly enable it in SQLPlus. You have to call dbms_output.enable in your code. If you do not do that, it is "as if it were not there". Dbms_output will just return - it won't do anything.

I'd prefer, INFINITELY prefer, to have the dbms_output in there - as opposed to not having it in there. If something goes wrong in production - they won't let you drop in a debug version. So, I say, go production WITH THE DEBUG VERSION.

Oracle does - you have our debug version of the database. It creates trace files, it has events you can set, it has V$ tables - these are all - without exception - debug code. Would you like us to strip it out? No, you really wouldn't

And your coworkers shouldn't either.


There are better tools then dbms_output for creating trace files though, you might consider a logging package that can be switched on and off with a fine degree of control, such as:

https://www.google.com/search?q=tyler+muth+logger

Rating

  (6 ratings)

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

Comments

Linking error

Shannon Severance, May 24, 2012 - 12:01 pm UTC

The link: https://forums.oracle.com/forums/thread.jspa?messageID=10354764� has a funny character at the end that results in an error.

Working link: https://forums.oracle.com/forums/thread.jspa?messageID=10354764
Tom Kyte
May 24, 2012 - 12:30 pm UTC

thanks!

I'll fix that up

A reader, May 24, 2012 - 12:18 pm UTC

Thank you for your kind response.
Though, I am the originator of that thread you mentioned.
;-)
Tom Kyte
May 24, 2012 - 12:35 pm UTC

I know, that is why I pointed it out.

The old "machine gun approach to asking questions"

Shoot out as many bullets as possible and see if you hit anything....

Tanmay, May 24, 2012 - 1:25 pm UTC

Yeah... But if you might have observed, there are also some different opinions in there.

There are some views that it is not a good practice to have them on production because of the buffer size limit and because it consumes resources.

Now, that is different from what you wrote.

Before that, I would like to clarify 'enabling' of dbms_output package.
I used SQL Developer 3.0
I disabled the package by issuing -
execute dbms_output.disable;


Then debugged my package in SQL Developer only in the same session (of course). I was still able to see the messages I wrote in dbms_output.put_line().

Tom Kyte
May 24, 2012 - 3:16 pm UTC

That is why this is "asktom" and not "ask anybody".

As I said: if you do NOT enable it (and it is not enabled by default, you have to go out of your way to do it), then

dbms_output just returns, it does nothing


there are no buffer limits, it just returns
there are no resources like memory taken, it just returns.
IT JUST RETURNS
it does nothing, it just RETURNS

that is not an opinion.

A view based not on fact is fiction :)

Then debugged my package in SQL Developer only in the same session (of course). I was still able to see the messages I wrote in dbms_output.put_line().


then something ENABLED IT. please, in your own application - call dbms_output in an infinite loop (without enabling it).

tell me - does it consume tons of memory? no, it won't, because IT JUST RETURNS

go into sqlplus, make sure it is dislabled (the default) - set serveroutput off

now, call dbms_output - do you see it???? no, you won't. because IT JUST RETURNS


go to production with dbms_output, I would personally want you to (or to use something more "sophisticated" like the logger package). but gosh darn it USE SOMETHING and GO PRODUCTION WITH IT.

I wouldn't want to accept "production code" that isn't instrumented. Think about this, long and hard think about this.

excellent as usual

George Joseph, May 24, 2012 - 10:17 pm UTC

The responses from Tom are related to real life coding expereiences, which is why this site is simply the best.

Now a days when people ask "hello, the screen gave me an error" and i can safely ask "what is the error description and the error line number you got".
Dont tell me it didnt come up since i know i coded it to get me these two vital information". Give me that and i shall fix your problem as swiftly as possible.

"There is an Error on Screen" doesnt convey anything

Tanmay Bansal, May 24, 2012 - 11:20 pm UTC

You are my man! \m/

Splendid answer.

Thank you so much!!!!!
:-)

Application Environment

Barry Chase, May 27, 2012 - 6:34 am UTC

Cautionary. The App environment, i.e. Oracle EBS, may have built-in provisions for displaying DBMS_OUTPUT. You might consider the use of debug flags on your api calls or even table drive the debug mode respective to each interface/job running that you wish to display debug information for. This way you can turn on when needed or leave on for a period if desired
Tom Kyte
May 27, 2012 - 12:36 pm UTC

absolutely:



There are better tools then dbms_output for creating trace files though, you might consider a logging package that can be switched on and off with a fine degree of control, such as:

https://www.google.com/search?q=tyler+muth+logger


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