【发布时间】:2021-10-16 23:37:19
【问题描述】:
我必须向 IT 部门的所有员工更新 20% 的加薪。 在 MySQL 工作台中。
创建下表: Emp(E_ID, E_Name, E_Dept, E_Salary)
在 Emp 表中插入适当的数据。 属性 E_Dept 包含诸如(IT、Accounts、Sales)之类的值。 编写一个增加 IT 员工工资的 PL-SQL 游标。部门 20%。
我写了查询,
create procedure up()
begin
DECLARE v_employee_id INT;
enter code hereDECLARE v_salary NUMERIC(8,2);
DECLARE v_last_emp INT DEFAULT 0;
delcare emp_cur cursor for select empid,salary from employee where dept = IT for update;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_last_emp=1;
START TRANSACTION;
open emp_cur;
emp_loop: LOOP
fetch emp_cur into v_employee_id, v_salary;
if v_last_emp then
leave emp_loop;
end if
update employee set salary = salary + salary * 0.20 where current of emp_cur;
end loop emp_loop;
close emp_cur;
set v_last_emp =0;
end;
【问题讨论】:
-
PL/SQL 仅适用于 Oracle,所以我不确定您的意思。
标签: mysql mysql-workbench