create table accounts(
id serial primary key,
name varchar(50) not null,
account numeric
);
insert into accounts values
(1,‘Tom’,‘9000’),
(2,‘Jerry’,‘9000’);
select * from accounts;
创建存储过程(真正的存储过程procedure)
存储过程和函数的区别:
- 存储过程标识符:procedure
函数标识符:function - 存储过程无需return返回值,函数必须有return返回值,
- 存储过程可以使用事物,函数中无法使用事物,
创建存储过程语法:
create or replace procedure 存储过程名(param_list)
language plpgsql
as declare变量名type[defaultvalue];beginsqlstatement;commit;end; declare 变量名 type [default value]; begin sql_statement; commit; end; declare变量名type[defaultvalue];

本文由数据开发工程师Lee撰写,介绍了PostgreSQL中存储过程的概念、区别于函数的特点,并提供了创建和调用存储过程的实例。通过示例展示了如何使用存储过程进行账户金额转移操作,以及调用后的数据变化。

1157

被折叠的 条评论
为什么被折叠?



