Difference between PUT & PUT_LINE in SQL

User defined sql functions enable sql developers to club the sql statements and logic together in a method, hence avoiding repetition of code and also helps in keeping the code organized and clean.

Like any other technology, while writing sql functions there is often a need to debug the code by printing data at various stages. The DBMS_OUTPUT package enables you to print messages and data using the PUT and PUT_LINE procedures.

PUT Procedure

Syntax:
DBMS_OUTPUT.PUT (item IN VARCHAR2);

Example:
DBMS_OUTPUT.PUT ('value: ' || value);
DBMS_OUTPUT.PUT ('Welcome to VerticalHorizons');

Note:
The PUT procedure that takes a NUMBER is obsolete but it is still supported for legacy reasons.

PUT_LINE Procedure
When you call PUT_LINE the item you specify is automatically followed by an end-of-line marker.

Syntax:
DBMS_OUTPUT.PUT_LINE (item IN VARCHAR2);

Example:
DBMS_OUTPUT.PUT_LINE ('value: ' || value);
DBMS_OUTPUT.PUT_LINE ('Welcome to VerticalHorizons');

Note:
The PUT_LINE procedure that takes a NUMBER is obsolete but it is still supported for legacy reasons.

These two procedures aid in debugging sql functions and turn out to be very useful while writing complex logic.

Please leave your footprints in comments section if there are better way of doing the things…!!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">