迷楚生迷疯了,拿段代码顶顶贴
BEGIN
IF :new.rcpt_no is not null AND :old.rcpt_no is null THEN
UPDATE pats_in_hospital SET
total_costs=DECODE(total_costs,null,0,total_costs)-:old.costs,
total_charges=DECODE(total_charges,null,0,total_charges)-:old.charges
WHERE patient_id=:old.patient_id AND visit_id=:old.visit_id;
ELSE
IF :new.rcpt_no is null and :old.rcpt_no is not null THEN
UPDATE pats_in_hospital SET
total_costs=DECODE(total_costs,null,0,total_costs)+:new.costs,
total_charges=DECODE(total_charges,null,0,total_charges)+:new.charges
WHERE patient_id=:old.patient_id AND visit_id=:old.visit_id;
ELSE
UPDATE pats_in_hospital SET
total_costs=DECODE(total_costs,null,0,total_costs)+:new.costs-:old.costs,
total_charges=DECODE(total_charges,null,0,total_charges)+:new.charges-:old.charges
WHERE patient_id=:old.patient_id AND visit_id=:old.visit_id;
END IF;
END IF;
END;
