伙计我不知道为什么我在这里得到这个错误是代码。什么精度需要int?我将整数分配给PATIENT_SSA。我试过把它分配给十进制(19,2),但它也不起作用。
CREATE TRIGGER TRIDOWYW
BEFORE INSERT ON PRESCRIPTION_BILLS
FOR EACH ROW
DECLARE
PATIENTID INT;
PHARMACY_SSA INT;
PATIENT_SSA INT;
PHARMACYID INT;
TOTAL_FOR_MEDICINE DOUBLE;
PATIENTINSURANCEPERCENT DOUBLE;
BEGIN
SELECT PATIENT_ID INTO PATIENTID
FROM PRESCRIPTIONS
WHERE PRESCRIPTION_ID = :NEW.PRESCRIPTION_ID;
SELECT PHARMACY_ID INTO PHARMACYID
FROM PRESCRIPTIONS
WHERE PRESCRIPTION_ID = :NEW.PRESCRIPTION_ID;
SELECT SSA_ID INTO PATIENT_SSA
FROM PATIENTS JOIN KIND_OF_INSURANCES USING (INSURANCE_ID)
WHERE PATIENT_ID=PATIENTID;
SELECT SSA_ID INTO PHARMACY_SSA
FROM CONTRACTS_WITH_PHARMACY
WHERE SSA_ID=PATIENT_SSA AND PHARMACY_ID = PHARMACYID AND SYSDATE BETWEEN BEGIN_DATE AND END_DATE;
SELECT SUM(MEDICINE.PRICE) AS SUM1 INTO TOTAL_FOR_MEDICINE
FROM MEDICINE_ON_PRESCRIPTION JOIN MEDICINE USING (MEDICINE_ID)
WHERE PRESCRIPTION_ID = :NEW.PRESCRIPTION_ID;
IF(PHARMACY_SSA)THEN
SELECT PERCENTAGE.PERCENTAGE_VALUE/100 INTO PATIENTINSURANCEPERCENT
FROM (PATIENTS JOIN KIND_OF_INSURANCES USING (INSURANCE_ID)) JOIN PERCENTAGE USING (PERCENTAGE_ID)
WHERE PATIENTS.PATIENT_ID = PATIENT_ID;
:NEW.TO_PAY_BY_PATIENT:= TOTAL_FOR_MEDICINE * PATIENTINSURANCEPERCENT;
:NEW.TO_PAY_BY_SSA := TOTAL_FOR_MEDICINE - :NEW.TO_PAY_BY_PATIENT;
ELSE
:NEW.TO_PAY_BY_PATIENT:= TOTAL_FOR_MEDICINE;
:NEW.TO_PAY_BY_SSA :=0;
END IF;
END;
/
答案 0 :(得分:1)
触发器有点奇怪,因为CREATE TRIGGER
是SQL,但正文是PL / SQL。当您收到类似这样的PL / SQL错误时,行号仅在PL / SQL部分内,因此您必须从DECLARE
开始计数。这使第六行成为TOTAL_FOR_MEDICINE
声明。
如图所示in the documentation,Oracles确实支持那里列出的ANSI类型,但是你需要关键字PRECISION:
DOUBLE PRECISION数据类型是一个二进制精度为126的浮点数。
所以你需要使用:
TOTAL_FOR_MEDICINE DOUBLE PRECISION;
您应该考虑所需的值,并且可以使用NUMBER数据类型,指定适当的精度和比例,以避免浮点类型的舍入错误。
答案 1 :(得分:0)
在你的情况下,最好用与表中定义相同的方式定义它:
DECLARE
PATIENTID PRESCRIPTIONS.PATIENT_ID%TYPE;
等等。
在大多数情况下,最好对列和变量使用NUMBER
数据类型。