我正在尝试在oracle中编写一个存储过程,将新数据插入到表中,但在插入数据之前,我希望它检查客户端是否正在进行可能相互冲突的处理。我一直在尝试使用IF语句来实现这个功能,但是一直不成功,这是我现在的代码:
CREATE OR REPLACE PROCEDURE FPRESC (
FP_ID VARCHAR2,
FTREAT_ID VARCHAR2,
FCLIENT_ID VARCHAR2,
FDOC_ID VARCHAR2)
AS
V_CLIENT_ID PRESCRIPTION.CLIENT_ID%TYPE;
V_CONFLICT TREATMENTS.CONFLICT%TYPE;
BEGIN
IF (FCLIENT_ID = V_CLINET_ID AND FTREAT_ID = V_CONFLICT)
BEGIN
DBMS_OUTPUT.PUT_LINE('CONFLICT');
END;
ELSE
BEGIN
INSERT INTO PRESCRIPTION (P_ID, TREAT_ID, CLIENT_ID, DOC_ID)
VALUES (FP_ID, FTREAT_ID, FCLIENT_ID, FDOC_ID);
END FPRESC;
以及我如何调用该程序的示例:
EXEC FPRESC ('P00011', 'T016', 'C00017', 'D006');
对于我应该改变什么或如何处理这个问题,我将不胜感激。
答案 0 :(得分:1)
CREATE OR REPLACE PROCEDURE FPRESC (
FP_ID VARCHAR2,
FTREAT_ID VARCHAR2,
FCLIENT_ID VARCHAR2,
FDOC_ID VARCHAR2)
AS
V_CLIENT_ID PRESCRIPTION.CLIENT_ID%TYPE;
V_CONFLICT TREATMENTS.CONFLICT%TYPE;
BEGIN
IF FCLIENT_ID = V_CLIENT_ID AND FTREAT_ID = V_CONFLICT THEN
DBMS_OUTPUT.PUT_LINE('CONFLICT');
ELSE
INSERT INTO PRESCRIPTION (P_ID, TREAT_ID, CLIENT_ID, DOC_ID)
VALUES (FP_ID, FTREAT_ID, FCLIENT_ID, FDOC_ID);
END IF;
END FPRESC;
答案 1 :(得分:0)
试试这个
CREATE OR REPLACE PROCEDURE FPRESC (
FP_ID VARCHAR2,
FTREAT_ID VARCHAR2,
FCLIENT_ID VARCHAR2,
FDOC_ID VARCHAR2)
AS
V_CLIENT_ID PRESCRIPTION.CLIENT_ID%TYPE;
V_CONFLICT TREATMENTS.CONFLICT%TYPE;
BEGIN
IF FCLIENT_ID = V_CLIENT_ID AND FTREAT_ID = V_CONFLICT THEN
BEGIN
DBMS_OUTPUT.PUT_LINE('CONFLICT');
END;
ELSE
BEGIN
INSERT INTO PRESCRIPTION (P_ID, TREAT_ID, CLIENT_ID, DOC_ID)
VALUES (FP_ID, FTREAT_ID, FCLIENT_ID, FDOC_ID);
END;
END IF;
END FPRESC;