数据库的存储过程

什么是存储过程?

为了方便使用而保存的一条或多条MySQL语句的集合


为什么要使用存储过程?

1.简化操作,将复杂的处理过程封装到一个单元内

2.保证了数据的完成性,自己或他人多次调用可以保证结果一致,不会出现错误

3.方便更改维护


简单创建一个存储过程

先使用     CREATE procedure  存储过程名称(参数列表)

begin  end  里面就是SQL语句和业务逻辑

CREATE procedure pdd_sum(a int ,b int)
begin 
declare c int;
if a is null
then set a=0;
end if;
if b is null
then set b=0;
end if;
set c=a+b;
select c;
end

调用存储过程

call pdd_sum(100,203);

删除存储过程

drop procedure if exists pdd_sum;

 

发布了29 篇原创文章 · 获赞 3 · 访问量 865

猜你喜欢

转载自blog.csdn.net/weixin_44616792/article/details/100985553