mysql建立存儲過程

##無參數存儲過程
delimiter //
create procedure myFist_proc() ## 建立存儲過程
begin
select stu_id from score where grade>80 and c_name='計算機';
select name from student where id in
(select stu_id from(select * from score where grade>80 and c_name='計算機')a
where a.stu_id in(select stu_id from score where grade>80 and c_name='英語'));
end;//
delimiter;
show create procedure myFist_proc();
call myFist_proc();it


##帶有輸出參數的存儲過程
delimiter //
create procedure mySecond_proc(out sumStudent int ) ## 建立存儲過程
begin
select count(*) into sumStudent from score where grade>80;
end;//
delimiter;
call mySecond_proc(@sumStudent);
select @sumStudent;select


##帶有輸入參數的存儲過程
delimiter //
create procedure myThird_proc(in minScore int ) ## 建立存儲過程
begin
select count(*) from score where grade>minScore;
end;//
delimiter;
call myThird_proc(90); 大於90的
select @sumStudent;im


##帶有輸入輸出參數的存儲過程
delimiter //
create procedure myFourth_proc(in minScore int,out sumStudent int ) ## 建立存儲過程
begin
select count(*) into sumStudent from score where grade>minScore;
end;//
delimiter;
call myFourth_proc(90,@sumStudent);
select @sumStudent;call

相關文章
相關標籤/搜索