create function countByDept(deptName varchar(20)) returns integer
begin
declare cnt integer;
select count(*) into cnt
from Stu
where Stu.Sdept=deptName;
end
MySQL 数据库方式:
use test;
create function CountByDept(deptName varchar(20))
returns INT
begin
declare cnt int;
select sum(1) into cnt from Stu t
where t.Sdept=deptName;
return cnt;
end