存储过程作用:
存储在数据库服务端供客户端使用的调用执行的SQL语句就是存储过程
格式:
sql 语句:
create procedure p_student
@dept char(20)
as
select sname,cname,grade
from student s join score sc on s.sno = sc.sno join course c on c.cno = sc.cno
where sdept = @dept
MySQL语句:
create procedure pr_add
(
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 as sum;
end;
执行存储过程:
单个或者知道序列顺序的使用:
Exec p_student ‘计算机系‘
多个参数的使用:
Exec p_student @sdept = ‘计算机系‘,@cname = ‘数学‘