我們試圖根據它租用的天數來計算出租車的TOTAL_COST的觸發器。租賃總成本是根據車輛的天數和成本計算的。總額增加12%的附加稅。如果租金超過10天,則從總費用中扣除15%的折扣。SQL觸發器更新始終爲空
這是我們的觸發器:
create or replace trigger L5_Q8
After Update on E2_RESERVATIONS
for each row
Declare
TOTALDAYS NUMBER(4);
TotalCostBeforeTax Number(8);
BEGIN
TOTALDAYS := (trunc(:NEW.END_DATE) - TRUNC(:NEW.START_DATE)) + 1;
IF(TOTALDAYS > 10) THEN
SELECT V.COST_PER_DAY * TOTALDAYS * 0.85
INTO TotalCostBeforeTax
from E2_Reservations R
join E2_Vehicle V on R.V_ID = V.V_ID;
END IF;
IF(TOTALDAYS <= 10) THEN
SELECT V.COST_PER_DAY * TOTALDAYS
INTO TotalCostBeforeTax
from E2_Reservations R
join E2_Vehicle V on R.V_ID = V.V_ID;
END IF;
TotalCostBeforeTax := TotalCostBeforeTax * 1.12;
UPDATE E2_RESERVATIONS SET TOTAL_COST = 10.1 WHERE ROWID IN (SELECT MAX(ROWID) FROM E2_RESERVATIONS);
END;
這些都是我們的表:
E2_RESERVATIONS:
E2_VEHICLE:
注意:'TotalCostBeforeTax'必須聲明爲'Number(8,2)'... –