GBSE存储过程
假设我们有一个员工表employees,包含字段employee_id(员工ID)、employee_name(员工姓名)、salary(工资)和department(部门)。现在我们希望创建一个存储过程,根据输入的部门名称,计算每个部门的平均工资
CREATE PROCEDURE calculate_average_salary(IN dept_name VARCHAR(255), OUT avg_salary DECIMAL(10, 2))
BEGIN
DECLARE total_salary DECIMAL(10, 2) DEFAULT 0;
DECLARE emp_count INT DEFAULT 0;
DECLARE done INT DEFAULT 0;
DECLARE cur CURSOR FOR SELECT salary FROM employees WHERE department = dept_name;
DECLARE CONTINUE</