oracle - 为员工分配等级的 PL/SQL 程序
问题描述
create or replace procedure p2
as
CURSOR c1 IS
SELECT salary
FROM employee1
FOR UPDATE;
BEGIN
FOR employee_rec IN c1 LOOP
exit when c1%notfound;
if salary>20000 then
update employee1 set grade='A' WHERE CURRENT OF c1;
if salary>15000 then
update employee1 set grade='B' WHERE CURRENT OF c1;
if salary>10000 then
update employee1 set grade='C' WHERE CURRENT OF c1;
if salary<10000 then
update employee1 set grade='D' WHERE CURRENT OF c1;
end if;
end if;
end if;
end if;
END LOOP;
END p2;
未声明薪水时出现错误如何使此代码更好地获得所需的输出?
解决方案
为什么不简单地这样:
update employee1 set grade=
case
when salary>20000 then 'A'
when salary>15000 then 'B'
when salary>10000 then 'C'
when salary<10000 then 'D'
ELSE grade -- keep existing grade value
end;
推荐阅读
- sql - 按 EntryDate 的 MSSQL 总和
- macos - nasm - 无法在 macOS Mojave 上将目标文件与 ld 链接
- android - 错误:android.permission.READ_PHONE_STATE
- java - 带有 ViewPagers oncreateView 的 Android 片段在错误片段中调用
- python - 如何将字符集应用于 Redis ConnectionPool?
- gstreamer - GStreamer 并排播放 3 个视频
- vue.js - 非 SPA 的 Vue 历史模式
- makefile - 没有数字的“make -j”是什么意思
- r - 将 Spark SQL 函数转换为“普通”R 代码
- c# - C# SharpDX compilefromfile 与嵌入式资源