1. Home
  2. Docs
  3. Oracle to PostgreSQL Migration
  4. PLSQL to plpgsql
  5. Migrating DBMS_OUTPUT.PUT_LINE

Migrating DBMS_OUTPUT.PUT_LINE

Oracle’s DBMS_OUTPUT package is typically used for debugging or for displaying output messages from PL/SQL anonymous blocks, stored procedures, packages or triggers. PUT_LINE is a procedure within  DBMS_OUTPUT  package that takes a VARCHAR2 data type as input parameter and places a line in the buffer which can be displayed on screen when you use  SET SERVEROUTPUT ON.

Examples:

--Example 1: Does not print anything
BEGIN
    DBMS_OUTPUT.PUT_LINE('Hello World!');
END;
/

PL/SQL procedure successfully completed.


--Example 2: Prints output to screen
SET serveroutput ON;

BEGIN
    DBMS_OUTPUT.PUT_LINE('Hello World!');
END;
/

Hello World!

PL/SQL procedure successfully completed.

Equivalent of DBMS_OUTPUT.PUT_LINE in PostgreSQL

In PostgreSQL, RAISE statement is used to report messages and raise errors. PostgreSQL provides level option to specify with RAISE that specifies the severity of the statement. Possible levels with  RAISE  are  DEBUGLOGNOTICEWARNINGINFO and EXCEPTION. You can get detail information and usage of different severity levels with RAISE statement in below article.

Examples:

Migrate Oracle database DBMS_OUTPUT.PUT_LINE to RAISE DEBUG in PostgreSQL.

DO $$
BEGIN
    RAISE DEBUG 'Hello World!';
END $$;

DO


SET client_min_messages = DEBUG;

DO $$
BEGIN
    RAISE DEBUG 'Hello World!';
END $$;

DEBUG:  Hello World!
DO

Points to remember

  • You can convert Oracle PL/SQL DBMS_OUTPUT.PUT_LINE to RAISE DEBUG in PostgreSQL.
  • You use SET serveroutput ON in Oracle to display the output in screen. Similarly you must use SET client_min_messages = DEBUG to print the output to screen in PostgreSQL.
Was this article helpful to you? Yes No

How can we help?