Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PL/SQL Alias for DBMS_OUTPUT.PUT_LINE()?

Simple question, is it possible to give an alias to the output function in the question title so that I can call something like trace('hello') rather than DBMS_OUTPUT.PUT_LINE('hello')?

I would like this because I use output to help with debugging and I am tired of typing that whole function name out and/or copy and pasting it all the time.

Thanks for your time.

like image 272
Griffin Avatar asked May 14 '11 10:05

Griffin


People also ask

What is DBMS_OUTPUT Put_line in PL SQL?

The Oracle dbms_output. put_line procedure allows you to write data to flat file or to direct your PL/SQL output to a screen.

Can we use DBMS_OUTPUT Put_line in function?

put_line doesn't work inside function.

What command should you try if DBMS_OUTPUT Put_line?

BEGIN dbms_output. put_line('Hello world! '); END; You can run this by pressing F5, or clicking Run Script.

Why do we use DBMS_OUTPUT Put_line?

The DBMS_OUTPUT package enables you to send messages from stored procedures, packages, and triggers. The PUT and PUT_LINE procedures in this package enable you to place information in a buffer that can be read by another trigger, procedure, or package.


1 Answers

Just create a procedure to wrap the call:

create or replace procedure trace(v_message in VARCHAR2)
as
begin
    dbms_output.put_line(v_message);
end;

Usage:

SQL> begin
  2  trace('hello');
  3  end
  4  ;
  5  /

PL/SQL procedure successfully completed.

SQL> set serverout on size 1000000
SQL> /
hello

PL/SQL procedure successfully completed.
like image 184
Datajam Avatar answered Sep 22 '22 19:09

Datajam