PostgreSQL 存储过程(函数)创建和基本语法

PostgreSQL官方文档

http://www.postgres.cn/docs/10/index.html

Postgresql过程语言官方文档
http://www.postgres.cn/docs/10/xplang.html

Postgresql查看当前版本
select version();

PostgreSQL函数创建格式

drop function if exists [函数名];
create function [函数名] ([参数]) returns [返回值] as
 $$
declare 
  [变量声明]
begin
  [sql逻辑]
end;
$$
language 'plpgsql';

示例1

create or replace function calculate (num1 int, num2 int, opr char(1)) returns int as
 $$
declare 
  num int;
begin
   --raise notice 'num1:%,num2:%;opr:%', num1, num2, opr;
   if opr = '-' then num := num1 - num2; 
   elseif opr = '+' then num := num1 + num2;
   elseif opr = 
  • 7
    点赞
  • 51
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值