Skip to main content

Avoid direct calls to DBMS_OUTPUT procedures

ZPA rule for PL/SQL and Oracle SQL · DbmsOutputPut

DBMS_OUTPUT writes to a buffer of the session that only a client that enables it reads, such as SQL*Plus with SET SERVEROUTPUT ON. Called from an application, a job or a trigger, the text is discarded, or kept in the buffer until the session ends: whatever the code meant to report is lost. Diagnostics belong in the application's logging, and messages for the user in the values the code returns or the errors it raises.

This rule reports calls to DBMS_OUTPUT.PUT and DBMS_OUTPUT.PUT_LINE, with or without the SYS schema, in main code. Test code is not checked.

Examples​

Noncompliant Code Example
create procedure purge_bins(p_days number) is
begin
delete from bin_history where moved_at < sysdate - p_days;
dbms_output.put_line(sql%rowcount || ' rows purged'); -- Noncompliant
end;
Compliant Solution
create procedure purge_bins(p_days number) is
begin
delete from bin_history where moved_at < sysdate - p_days;
log_pkg.info('purge_bins', sql%rowcount || ' rows purged');
end;