Skip to Main Content
  • Questions
  • Printing a name with out using dbms_output.put_line

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Rajendra.

Asked: January 21, 2017 - 6:56 am UTC

Last updated: January 23, 2017 - 3:18 am UTC

Version: 11g

Viewed 1000+ times

You Asked

Hi Tom,

Recently in one of the interview i was asked whether i can print any thing with out using dbms_output.put_line in Pl/SQL

I am having a little experience in Pl/SQL , As per my knowledge i think we cannot. But please let me know if there is a way to do so which helps me to correct my understanding.

Thanks
Raj

and Connor said...

Really depends what they mean by "print" (ie, I think its a silly question for an interviewer to ask).

dbms_output does not really "print". It simply stores data in an array, and sqlplus *know* this. So when a plsql call is finished, sqlplus looks inside that array and if there is anything present (and 'serverout' is on) retrieves it and puts it on the screen.

So alternatives could be:

1) store the info in a global temporary table, do a select to fetch it
2) store the info in a plsql nested table, do a select to fetch it
3) use utl_file to write to a file

Hope this helps.

Rating

  (3 ratings)

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

Comments

Rajendra Kalepu, January 22, 2017 - 6:26 am UTC

Thank you Tom . The explanation is very clear . I will try the given suggestions in my sql developer

Rajendra Kalepu, January 22, 2017 - 6:26 am UTC

Thank you Tom . The explanation is very clear . I will try the given suggestions in my sql developer

Trick question

Jeffrey Kemp, January 23, 2017 - 3:10 am UTC

The "correct" answer to this silly question might probably have been something like:

dbms_output.put('any thing');
dbms_output.new_line;

Connor McDonald
January 23, 2017 - 3:18 am UTC

Indeed. Thanks for stopping by.

More to Explore

DBMS_OUTPUT

More on PL/SQL routine DBMS_OUTPUT here