Wednesday, 12 August 2020

How To Display Output Message Like DBMS_OUTPUT.PUT_LINE In PostgreSQL Us...


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 Oracle Using PostgreSQL || Learn PL/pgSQL
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);


Tuesday, 11 August 2020

How To Create A Stored Procedure And Return Multiple Values From The Sto...



-- purpose is to return multiple values (more than one value) from a stored procedure

-- in PostgreSQL


How To Create A Stored Procedure And Return Multiple Values From The Stored Procedure In PostgreSQL

In this comprehensive tutorial, we’ll show you how to create a stored procedure in PostgreSQL that returns multiple values. Stored procedures are an essential tool in database management, allowing you to encapsulate complex logic and reuse it throughout your applications.

We begin by explaining the basics of stored procedures in PostgreSQL, including the syntax and the different ways to return values. You’ll learn how to declare variables, use the OUT parameters, and return multiple results from a single procedure. We’ll also cover how to call the stored procedure from pgAdmin and SQL Shell (psql), making sure you’re comfortable executing these procedures in different environments.

This video is ideal for developers, database administrators, and anyone looking to deepen their understanding of PostgreSQL. By the end of the tutorial, you’ll have the skills to create your own stored procedures that can return multiple values, enhancing the efficiency and flexibility of your database operations.

PostgreSQL, stored procedure, multiple values, PostgreSQL tutorial, PLpgSQL, pgAdmin, database development, SQL commands, database management, returning multiple values


CREATE OR REPLACE PROCEDURE public.testing_procedure(p_num1 IN numeric,p_num2 IN numeric,p_sum INOUT numeric,p_mult INOUT numeric,p_div INOUT numeric)

LANGUAGE 'plpgsql'

AS $BODY$

DECLARE

BEGIN

p_sum := p_num1 + p_num2;

p_mult := p_num1 * p_num2;

BEGIN

p_div := p_num1/p_num2;

EXCEPTION WHEN OTHERS THEN

p_div := 0;

END;

END;

$BODY$;



CALL public.testing_procedure(10,0,null,null,0);







CREATE OR REPLACE PROCEDURE public.testing_procedure(p_num1 IN numeric,p_num2 IN numeric,p_sum INOUT numeric,p_mult INOUT numeric,p_div INOUT text)

LANGUAGE 'plpgsql'

AS $BODY$

DECLARE

BEGIN

p_sum := p_num1 + p_num2;

p_mult := p_num1 * p_num2;

BEGIN

p_div := p_num1/p_num2;

EXCEPTION WHEN OTHERS THEN

p_div := 'You cannot divide a value by zero';

END;

END;

$BODY$;



CALL public.testing_procedure(10,0,null,null,'0');


How To Create A Stored Procedure With Parameter Modes IN INOUT OUT Modes...



How To Create A Stored Procedure With Parameter Modes IN INOUT OUT Modes In Postgresql || PL/pgSQL

-- purpose is to create a stored procedure with parameter mode (IN, INOUT) and call it

-- IN Only Input and it is default

-- OUT Only Output, only OUT is not allowed in Stored Procedure in PostgreSQL

-- INOUT Input + Output

In this video tutorial, you’ll learn how to create stored procedures in PostgreSQL using different parameter modes: IN, INOUT, and OUT. These parameter modes are crucial for controlling the flow of data within your stored procedures and can greatly enhance the flexibility and power of your database functions.

We start by explaining the purpose of each parameter mode:

  • IN: This mode allows you to pass data into the procedure.
  • OUT: This mode is used to return data from the procedure.
  • INOUT: This mode allows a parameter to be passed in and modified within the procedure, then returned.

After covering the basics, we dive into practical examples where you’ll see how to implement these modes in a stored procedure using PL/pgSQL. You’ll also learn how to call these procedures from pgAdmin and SQL Shell (psql), ensuring you can apply these techniques in real-world scenarios.

This tutorial is designed for database administrators, developers, and anyone interested in advancing their PostgreSQL knowledge. By the end of this video, you’ll have a solid understanding of how to use parameter modes effectively within your stored procedures, allowing for more dynamic and reusable database functions.

PostgreSQL, stored procedure, parameter modes, IN parameter, OUT parameter, INOUT parameter, PLpgSQL, PostgreSQL tutorial, database management, SQL commands, pgAdmin


CREATE OR REPLACE PROCEDURE public.testing_procedure(p_num1 IN numeric,p_num2 IN numeric, p_sum INOUT numeric)

LANGUAGE 'plpgsql'

AS $BODY$

DECLARE

BEGIN

p_sum := p_num1 + p_num2;

END;

$BODY$;


CALL public.testing_procedure(13,10,-1);


CREATE OR REPLACE PROCEDURE public.testing_procedure(p_num1 IN numeric,p_num2 IN numeric, p_sum INOUT numeric,p_mult INOUT numeric)

LANGUAGE 'plpgsql'

AS $BODY$

DECLARE

BEGIN

p_sum := p_num1 + p_num2;

p_mult := p_num1 * p_num2;

END;

$BODY$;


CALL public.testing_procedure(3,0,-1,-1);

How To Create A Stored Procedure And Insert Data Into A Table By Calling...




How To Create A Stored Procedure And Insert Data Into A Table By Calling/Using The Stored Procedure

In this tutorial, you’ll master the process of creating a stored procedure in PostgreSQL and learn how to insert data into a table by calling this procedure. Stored procedures are essential for encapsulating complex SQL operations, and this video will guide you through each step of the process.

We begin by introducing the concept of stored procedures and their benefits, particularly in terms of code reuse and simplifying database management. You'll see a detailed explanation of how to define a stored procedure in PL/pgSQL, the procedural language of PostgreSQL.

Next, we focus on a practical example: creating a stored procedure that inserts data into a specific table. This part of the video will show you:

  • How to declare the procedure.
  • How to define the input parameters that will pass the data to be inserted.
  • How to write the SQL commands within the procedure to perform the data insertion.

Finally, you’ll learn how to call this stored procedure from both pgAdmin and SQL Shell (psql), ensuring that you can apply this knowledge in your daily database management tasks.

This tutorial is perfect for database administrators, developers, and anyone looking to improve their PostgreSQL skills. By the end of the video, you’ll have the knowledge to efficiently create and utilize stored procedures for data manipulation in PostgreSQL.

PostgreSQL, stored procedure, insert data, SQL, table insertion, PLpgSQL, PostgreSQL tutorial, database management, pgAdmin, SQL Shell, data manipulation

-- the purpose is to create a simple stored procedure in PostgreSQL

-- and Insert Data in the table by calling it using pgAdmin
CREATE TABLE public.testing_table (dummy_column text);
CREATE OR REPLACE PROCEDURE public.testing_procedure(p_msg text)
LANGUAGE 'plpgsql'
AS $BODY$
DECLARE
BEGIN
INSERT INTO public.testing_table(dummy_column) VALUES('Before Inserting Parameter Value');
INSERT INTO public.testing_table(dummy_column) VALUES (p_msg);
INSERT INTO public.testing_table(dummy_column) VALUES('After Inserting Parameter Value');
END;
$BODY$;
SELECT * FROM public.testing_table;
DELETE from public.testing_table;

CALL public.testing_procedure('Hello Akram, How are you?');
Before Inserting
the message I pass as a parameter
After Inserting...

How To Resolve/Fix Issue Could Not Connect To Server Connection Refused ...




Only 3.9% of viewers are subscribing to my channel 😓.
I request you to please give click on Subscribe button.
It really helps me grow 😢.



How To Resolve/Fix Issue Could Not Connect To Server Connection Refused In PostgreSQL pgAdmin 4
How To resolve Issue Application Server Could Not Be Contacted In PostgreSQL

Sunday, 9 August 2020

Overloading Of A Stored Function In PostgreSQL || Stored Function Overlo...



Only 3.9% of viewers are subscribing to my channel 😓.
I request you to please give click on Subscribe button.
It really helps me grow 😢.



Overloading Of A Stored Function In PostgreSQL || Stored Function Overloading || PL/pgSQL Tutorials



CREATE OR REPLACE FUNCTION public.testing_function(p_num1 numeric, p_num2 numeric)

RETURNS numeric

LANGUAGE 'plpgsql'

COST 100

VOLATILE

AS $BODY$

DECLARE

v_result numeric;

BEGIN

v_result := p_num1 + p_num2;



RETURN v_result;

END;

$BODY$;







CREATE OR REPLACE FUNCTION public.testing_function(p_num1 numeric, p_num2 numeric,p_num3 numeric)

RETURNS numeric

LANGUAGE 'plpgsql'

COST 100

VOLATILE

AS $BODY$

DECLARE

v_result numeric;

BEGIN

v_result := p_num1 + p_num2 + p_num3;



RETURN v_result;

END;

$BODY$;





CREATE OR REPLACE FUNCTION public.testing_function(p_num1 numeric, p_num2 numeric,p_num3 numeric,p_num4 numeric)

RETURNS numeric

LANGUAGE 'plpgsql'

COST 100

VOLATILE

AS $BODY$

DECLARE

v_result numeric;

BEGIN

v_result := p_num1 + p_num2 + p_num3 + p_num4;



RETURN v_result;

END;

$BODY$;





SELECT public.testing_function(14,5);



SELECT public.testing_function(14,10,50);



SELECT public.testing_function(10,20,30,50);


Overloading Of A Stored Procedure In PostgreSQL | Stored Procedure Overl...




Only 3.9% of viewers are subscribing to my channel 😓.
I request you to please give click on Subscribe button.
It really helps me grow 😢.





Overloading Of A Stored Procedure In PostgreSQL | Stored Procedure Overloading | PL/pgSQL Tutorials



CREATE TABLE public.testing(demo_column text);



CREATE OR REPLACE PROCEDURE public.testing_procedure(p_msg text)

LANGUAGE 'plpgsql'

AS $BODY$

DECLARE

BEGIN

INSERT INTO public.testing(demo_column) VALUES (p_msg);

END;

$BODY$;







CREATE OR REPLACE PROCEDURE public.testing_procedure(p_num1 numeric, p_num2 numeric)

LANGUAGE 'plpgsql'

AS $BODY$

DECLARE

v_result numeric;

BEGIN

v_result := p_num1+p_num2;

INSERT INTO public.testing(demo_column) VALUES ('The Sum is '||v_result);

END;

$BODY$;





CREATE OR REPLACE PROCEDURE public.testing_procedure(p_num1 numeric, p_num2 numeric,p_num3 numeric)

LANGUAGE 'plpgsql'

AS $BODY$

DECLARE

v_result numeric;

BEGIN

v_result := p_num1+p_num2 +p_num3;

INSERT INTO public.testing(demo_column) VALUES ('The Sum is '||v_result);

END;

$BODY$;







CALL public.testing_procedure('Hello Akram');



CALL public.testing_procedure(3,5);



CALL public.testing_procedure(3,5,67);



SELECT * FROM public.testing;






How To Handle Exception In A Stored Procedure In PostgreSQL || PL/pgSQL ...




Only 3.9% of viewers are subscribing to my channel 😓.
I request you to please give click on Subscribe button.
It really helps me grow 😢.



The Purpose Is To Handle Exception In A Stored Procedure In PostgreSQL || PL/pgSQL Tutorials Exception Handling



-- without exception block



CREATE TABLE public.testing (demo_column text);



CREATE OR REPLACE PROCEDURE public.testing_procedure(p_num1 numeric,p_num2 numeric)

LANGUAGE 'plpgsql'

AS $BODY$

DECLARE

v_result numeric;

BEGIN

v_result := p_num1/p_num2;

INSERT INTO public.testing(demo_column) VALUES(v_result);

END;

$BODY$;



CALL public.testing_procedure(100,0);



SELECT * from public.testing;









-- with exception block



CREATE TABLE public.testing (demo_column text);



CREATE OR REPLACE PROCEDURE public.testing_procedure(p_num1 numeric,p_num2 numeric)

LANGUAGE 'plpgsql'

AS $BODY$

DECLARE

v_result text;

BEGIN

BEGIN

v_result := p_num1/p_num2;

EXCEPTION WHEN OTHERS THEN

v_result := 'You cannot divide a number by zero.';

END;

INSERT INTO public.testing(demo_column) VALUES(v_result);



END;

$BODY$;



CALL public.testing_procedure(100,20);



SELECT * from public.testing;


How To Create A Simple Parameterized Stored Procedure In PostgreSQL And ...



Only 3.9% of viewers are subscribing to my channel 😓.
I request you to please give click on Subscribe button.
It really helps me grow 😢.




-- purpose is to create a simple parameterized stored procedure in postgreSQL

-- and call it using pgAdmin



CREATE TABLE public.testing (demo_column text);



CREATE OR REPLACE PROCEDURE public.testing_procedure(p_msg text)

LANGUAGE 'plpgsql'

AS $BODY$

DECLARE

BEGIN

INSERT into public.testing(demo_column) values(p_msg);

END;

$BODY$;



call public.testing_procedure('Hello Akram, We are watching Knowledge 360');



SELECT * from public.testing;

How To Create A Simple Stored Procedure In PostgreSQL And Call Using pgA...




Only 3.9% of viewers are subscribing to my channel 😓.
I request you to please give click on Subscribe button.
It really helps me grow 😢.



-- purpose is to create a simple stored procedure in postgreSQL

-- and call it using pgAdmin





CREATE TABLE public.testing (demo_column text);





CREATE OR REPLACE PROCEDURE public.testing_procedure()

LANGUAGE 'plpgsql'

AS $BODY$

DECLARE

v_msg text;

BEGIN

v_msg := 'Hello Akram, We are watching Knowledge 360';



Insert into public.testing(demo_column) values (v_msg);

END;

$BODY$;





call public.testing_procedure();





SELECT * from public.testing;


Saturday, 8 August 2020

How To Handle Exception In A Stored Function/Procedure In PostgreSQL | E...




Only 3.9% of viewers are subscribing to my channel 😓.
I request you to please give click on Subscribe button.
It really helps me grow 😢.



-- without exception block

-- purpose is to handle exception in a stored function in PostgreSQL and call it



SELECT public.testing_function(100,0);



CREATE OR REPLACE FUNCTION public.testing_function(p_num1 numeric, p_num2 numeric)

RETURNS numeric

LANGUAGE 'plpgsql'

COST 100

VOLATILE

AS $BODY$

DECLARE

v_result numeric;

BEGIN

v_result := p_num1/p_num2;

RETURN v_result;

END;

$BODY$;







---with exception block



SELECT public.testing_function(100,0);



CREATE OR REPLACE FUNCTION public.testing_function(p_num1 numeric, p_num2 numeric)

RETURNS text

LANGUAGE 'plpgsql'

COST 100

VOLATILE

AS $BODY$

DECLARE

v_result text;

BEGIN

BEGIN

v_result := p_num1/p_num2;

EXCEPTION WHEN OTHERS THEN

v_result := 'You cannot divide by Zero, try Again';

END;



RETURN v_result;

END;

$BODY$;


How To Create A Parameterized Stored Function In PostgreSQL || Pass Para...



Only 3.9% of viewers are subscribing to my channel 😓.
I request you to please give click on Subscribe button.
It really helps me grow 😢.




SELECT public.testing_function(101,'Hello Akram');


CREATE OR REPLACE FUNCTION public.testing_function(p_num numeric,p_msg text)



RETURNS text

LANGUAGE 'plpgsql'



COST 100

VOLATILE



AS $BODY$



DECLARE

v_return_msg text;

BEGIN



v_return_msg := p_msg ||' '||p_num;



return v_return_msg;



END;

$BODY$;


How To Create A Stored Function In PostgreSQL And Call Stored Function I...




Only 3.9% of viewers are subscribing to my channel 😓.
I request you to please give click on Subscribe button.
It really helps me grow 😢.



SELECT public.testing_function();



CREATE OR REPLACE FUNCTION public.testing_function()



RETURNS text

LANGUAGE 'plpgsql'



COST 100

VOLATILE



AS $BODY$



DECLARE

v_return_msg text;

BEGIN



v_return_msg := 'Hello Akram';



return v_return_msg;



END;

$BODY$;