Home > Net >  How to create procedure and call/Execute in PostgreSQL
How to create procedure and call/Execute in PostgreSQL

Time:01-06

How to create procedure and call/Execute in PostgreSQL

How to create procedure and call/Execute in PostgreSQL

CodePudding user response:

To return a result "table", use a function not a procedure:

create function Proc_StudentLogin(Sid bigint)
  returns setof students
as
$Body$
  select * from students where id = sid;
$Body$
language sql
stable;
-- Use function:
select * 
from Proc_StudentLogin(1);

CodePudding user response:

--Create Procedure

Create procedure Proc_StudentLogin(

Sid bigint,

inout get_result refcursor)

Language 'plpgsql'

AS $Body$

Begin

open get_result for 

Select * from Students where id = sid;

End

$Body$;



--Call procedure

Call Proc_StudentLogin(1,'result');

fetch all in "result";
  • Related