5

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.

MatthewMartin
  • 32,326
  • 33
  • 105
  • 164
Griffin
  • 13,184
  • 4
  • 29
  • 43

2 Answers2

7

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.
Datajam
  • 4,141
  • 2
  • 23
  • 25
  • 1
    +1. I often define a procedure similar to this directly in the `DECLARE` section of PL/SQL blocks (when I don't want the hassle of creating a schema-level procedure). – Adam Paynter May 14 '11 at 12:39
  • Another benefit is that you can put an INSERT statement in the procedure to write the message to a log table too. – Datajam May 14 '11 at 12:52
2

Use a macro to type it for you.

I'm using PLSQL Developer and whenever I want dbms_output.put_line I type ctrl-D. This way I don't have to depend on the existence of a function with a shorter name. It just works whatever I'm working on.

Rene
  • 10,391
  • 5
  • 33
  • 46