If you’re accustomed to using Oracle’s DBMS_OUTPUT.PUT_LINE
to display messages during the execution of your scripts, you might wonder how to do something similar in PostgreSQL. This video tutorial is here to help! We’ll walk you through the process of using PL/pgSQL's RAISE NOTICE
within pgAdmin, allowing you to display output messages that are crucial for debugging and monitoring your stored procedures.
We start by exploring the basics of PL/pgSQL, PostgreSQL's procedural language. Then, we’ll demonstrate how to write simple functions and procedures that include output messages using the RAISE NOTICE
command. This approach is especially useful for those who are transitioning from Oracle to PostgreSQL and need a familiar way to track their code execution.
By the end of this tutorial, you’ll have a clear understanding of how to implement and use output messages in PostgreSQL, enabling you to better monitor, debug, and refine your database scripts in pgAdmin.
PostgreSQL, PLpgSQL, pgAdmin, RAISE NOTICE, DBMS_OUTPUT.PUT_LINE, SQL commands, PostgreSQL debugging, database monitoring, PLpgSQL tutorials, PostgreSQL output messages
How To Display Output Message Like DBMS_OUTPUT.PUT_LINE In PostgreSQL Using PgAdmin | Learn PL/pgSQL
-- The Purpose is to Display Message like DBMS_OUTPUT.PUT_LINE
-- of Oracle in PostgreSQL
CREATE OR REPLACE PROCEDURE public.proc(p_num1 IN numeric,p_num2 IN numeric)
LANGUAGE 'plpgsql'
AS $BODY$
DECLARE
v_sum numeric;
v_mult numeric;
v_div numeric;
BEGIN
v_sum := p_num1 + p_num2;
v_mult := p_num1 * p_num2;
BEGIN
v_div := TRUNC(p_num1/p_num2);
EXCEPTION WHEN OTHERS THEN
v_div := 0;
END;
RAISE NOTICE 'The Sum is : %',v_sum;
RAISE NOTICE 'The Multiplication is : %',v_mult;
RAISE NOTICE 'The Division is : %',v_div;
END;
$BODY$;
CALL public.proc(10,2);