我有一个存储过程,提示用户输入并存储/更新我的表。我的问题是,当尝试在输入数字时添加限制时,它不能按计划工作。
这是表格:
Drop table incident;
CREATE TABLE INCIDENT
(ICD_ID VARCHAR2 (8) NOT NULL PRIMARY KEY,
PLR_ID VARCHAR2 (11),
M_ID VARCHAR2 (10),
PP_ID VARCHAR2 (10),
I_POINTS NUMBER (8));
INSERT INTO INCIDENT VALUES
('ICD01', 'CHE01', 'M01', 'PP01', NULL);
INSERT INTO INCIDENT VALUES
('ICD02', 'CHE03', 'M07', 'PP02', NULL);
INSERT INTO INCIDENT VALUES
('ICD03', 'CHE03', 'M04', 'PP03', NULL);
INSERT INTO INCIDENT VALUES
('ICD04', 'KLN04', 'M07', 'PP02', NULL);
INSERT INTO INCIDENT VALUES
('ICD05', 'CHE01', 'M04', 'PP03', NULL);
出现提示时,我输入 ICD_ID (例如 'ICD03') *必须是大写* 条目。
步骤:
DECLARE
v_icd_id incident.icd_id%type := &INCIDENT_ID;
v_inc_I_POINTS incident.i_points%type := &PENALTY_POINTS;
v_I_POINTS incident.I_POINTS%type;
V_PP_ID INCIDENT.PP_ID%TYPE;
E_TOO_MANY_POINTS exception;
E_UPDATE_HIGH exception;
E_A exception;
E_B exception;
E_C exception;
BEGIN
SELECT I_POINTS INTO v_I_POINTS
FROM incident WHERE icd_id = v_icd_id;
IF v_I_POINTS > 10 THEN
RAISE E_UPDATE_HIGH;
END IF;
IF v_inc_I_POINTS >10 THEN
RAISE E_TOO_MANY_POINTS;
END IF;
IF V_PP_ID = 'PP03' OR V_INC_I_POINTS > 10 OR V_INC_I_POINTS < 10 THEN
RAISE E_A;
END IF;
UPDATE incident SET i_points = (v_inc_i_points + NVL(i_points,0))
WHERE icd_id=v_icd_id;
DBMS_OUTPUT.PUT_LINE('');
DBMS_OUTPUT.PUT_LINE('=====================');
DBMS_OUTPUT.PUT_LINE('PENALTY POINTS UPDATED!');
DBMS_OUTPUT.PUT_LINE('=====================');
DBMS_OUTPUT.PUT_LINE('');
EXCEPTION
WHEN E_TOO_MANY_POINTS THEN
DBMS_OUTPUT.PUT_LINE('==========================================================');
DBMS_OUTPUT.PUT_LINE('TOO MANY POINTS ALLOCATED THERE! ACTION ABORTED.');
DBMS_OUTPUT.PUT_LINE('==========================================================');
WHEN E_UPDATE_HIGH THEN
DBMS_OUTPUT.PUT_LINE('=============================================================');
DBMS_OUTPUT.PUT_LINE('CAN NOT STORE THAT MANY PENALTY POINTS THERE! ACTION ABORTED.');
DBMS_OUTPUT.PUT_LINE('=============================================================');
WHEN E_A THEN
DBMS_OUTPUT.PUT_LINE('=============================================================');
DBMS_OUTPUT.PUT_LINE('CAN ONLY ALLOCATED 10 POINTS HERE! ACTION ABORTED.');
DBMS_OUTPUT.PUT_LINE('=============================================================');
WHEN E_B THEN
DBMS_OUTPUT.PUT_LINE('=============================================================');
DBMS_OUTPUT.PUT_LINE('CAN ONLY ALLOCATED 5 POINTS HERE! ACTION ABORTED.');
DBMS_OUTPUT.PUT_LINE('=============================================================');
WHEN E_C THEN
DBMS_OUTPUT.PUT_LINE('=============================================================');
DBMS_OUTPUT.PUT_LINE('CAN ONLY ALLOCATED 1 POINTS HERE! ACTION ABORTED.');
DBMS_OUTPUT.PUT_LINE('=============================================================');
END;
/
我要完成的工作:
是为了防止人们在 PP_ID 为“PP03”的情况下输入大于 10 且小于 10 的值。
为此,我申请了:
IF V_PP_ID = 'PP03' OR V_INC_I_POINTS > 10 OR V_INC_I_POINTS < 10 THEN
RAISE E_A;
END IF;
这很好用,但是当我添加另一个限制时:
为了防止人们在 PP_ID 为“PP02”的情况下输入大于 5 且小于 5 的值。
IF V_PP_ID = 'PP02' OR V_INC_I_POINTS > 5 OR V_INC_I_POINTS < 5 THEN
RAISE E_B;
END IF;
或者
为了防止人们在 PP_ID 为“PP01”的情况下输入大于 1 且小于 1 的值。
IF V_PP_ID = 'PP01' OR V_INC_I_POINTS > 1 OR V_INC_I_POINTS < 1 THEN
RAISE E_C;
END IF;
它不起作用,只遵循第一个。我该如何克服呢?提前致谢。非常感谢您的帮助。