postgres讲义12_创建存储过程

PostgreSQL存储过程也称为函数

create or replace function efu.totalRecords()

returns integer AS $total$

declare  total integer;

begin

            select count(*) into total from efu.company;

            return total;

end;

$total$ language plpgsql;

一个名为“totalrecords”的函数被创建。现在

postgres讲义12_创建存储过程_第1张图片

解说

efu.totalRecords  指定函数的名称

returns 指定要从函数返回的数据类型

declare  变量

plpgsql 它指定实现该函数的语言的名称

 

来执行一个调用这个函数并检查efu.company表中的记录,如下所示 -

select efu.totalRecords()

postgres讲义12_创建存储过程_第2张图片

你可能感兴趣的:(postgres)