我有三张桌子
患者表的主键在dependent和patient_visit表中用作外键。我需要在患者台上触发,在删除之前检查子表中的patient_id。 至于现在我已经创建了一个触发器,但它没有工作。
create or replace trigger deletePatient
before delete on patient
for each row
declare
v_count number(5);
v_count1 number(5);
begin
select count(patient_id)
into v_count
from dependent
where patient_id = :old.patient_id;
if v_count > 0 then
raise_application_error(-20444,'Cannot Delete record');
else select count(patient_id)
into v_count1
from patient_visit
where patient_id = :old.patient_id;
if v_count1 > 0 then
raise_application_error(-20434,'Cannot Delete record');
else dbms_output.put_line('Deletion Successful');
end if;
end if;
end;
/