CREATE TABLE employees
(
ENO NUMBER (3),
ENAME VARCHAR2 (35),
HIREDATE DATE,
SAL NUMBER (6),
EXPR NUMBER (3),
DEPTNO NUMBER (3),
JOB VARCHAR2 (20),
COMM NUMBER (10)
)
,这是我的表结构,我的“COMM”列没有任何值,我想通过使用过程添加基于“SAL”列的值,写一个程序来添加值
答案 0 :(得分:0)
CREATE OR REPLACE PACKAGE XX_UPDATETBEMP
AS
PROCEDURE XX_UPDATECOMM;
END XX_UPDATETBEMP;
CREATE or REPLACE PACKAGE BODY XX_UPDATETBEMP
IS
PROCEDURE XX_UPDATECOMM
IS
BEGIN
UPDATE emp
SET comm =
CASE
WHEN sal BETWEEN 30000 AND 50000 THEN .20 * sal
WHEN sal BETWEEN 50000 AND 70000 THEN .15 * sal
WHEN sal BETWEEN 70000 AND 100000 THEN .10 * sal
END;
END XX_UPDATECOMM;
END XX_UPDATETBEMP;
答案 1 :(得分:0)
PROCEDURE XX_UDCOMMS IS
CURSOR C_TBEMP IS
SELECT * FROM XX_TBEMP;
l_comm NUMBER;
BEGIN
FOR C IN C_TBEMP LOOP
l_comm := NULL;
IF C.SAL BETWEEN 30000 AND 49999 THEN
l_comm := c.sal * 0.2;
ELSIF C.SAL BETWEEN 50000 AND 79999 THEN
l_comm := c.sal * 0.15;
ELSIF C.SAL BETWEEN 80000 AND 99999 THEN
l_comm := c.sal * 0.1;
END IF;
UPDATE XX_TBEMP SET COMM = l_comm WHERE c.eno = eno;
END LOOP;
end;