语法:
create procedure 存储过程名称(参数列表) begin sql 语句 ; end
无参->请编写 SQL 语句,创建一个名为 GetTotalTeacher 的存储过程,声明一个变量 totalTeacher 默认值为 0,将 teachers 表中的教师人数赋值给该变量:
create procedure GetTotalTeacher() begin select count(*) totalTeacher from teachers; end
创建存储过程 stu(),查询 students 表所有学生信息:
CREATE PROCEDURE stu() BEGIN SELECt * from students; end
–调用存储过程
stu call stu();
– 删除存储过程,删除的时候不用写名字后面的()
DROP PROCEDURE stu; drop PROCEDURE if EXISTS stu;
请编写 SQL 语句,创建一个名为 UpdateStudentCount 的存储过程,实现更新 Django 的课程的人数。该存储过程有两个参数:
count:是 INOUT 参数,指定学生人数
des:是 IN 参数,指定毕业的人数
我们会调用该存储过程,给 Django 课程毕业 100 人
create procedure UpdateStudentCount( INOUT count int, IN des int ) begin set count=count-des; update courses set student_count=count where name= 'Django'; end;



