我有一个基于数据库(Oracle)的项目,创建一个汽车租赁店。到目前为止,一切都很顺利,但我被一个触发器卡住了,它必须在租车和归还日期之间检查客户和车辆,这样已经租车的客户就不能再租车,而另一个客户就不能再租车了。
租金表:
CREATE TABLE RentAuto
(
auto_id INT,
customer_id INT,
employee_id INT,
date_rent DATE,
date_return DATE,
rent_days VARCHAR2(5)
);
汽车表:
CREATE TABLE Automobile
(
auto_id INTEGER NOT NULL,
year_of_production VARCHAR(10),
auto_current_km VARCHAR(20),
price_per_day VARCHAR(20),
color_id INT,
is_auto_av INT,
model_id INT,
PRIMARY KEY(auto_id)
);
在表格中插入:
INSERT INTO RentAuto (auto_id,customer_id,employee_id,date_rent,date_return, rent_days)
VALUES(14,13,3,TO_DATE(sysdate, 'dd-mm-yyyy'), '29-03-2022','2');
我在下面写的触发器在IF语句中给了我一个错误,我不知道如何修复它。
(
PLS-00201:标识符“新”。必须声明“客户ID”
create or replace TRIGGER RENTINGTRIGGER
BEFORE INSERT OR UPDATE OF AUTO_ID,CUSTOMER_ID,DATE_RENT,DATE_RETURN ON RENTAUTO
FOR EACH ROW
BEGIN
IF RENTAUTO.CUSTOMER_ID = :NEW.CUSTOMER_ID
and ((new.DATE_RENT >= RentAuto.DATE_RETURN and new.DATE_RENT < RentAuto.DATE_RETURN)
or (new.DATE_RETURN > RentAuto.DATE_RENT and new.DATE_RETURN < RentAuto.DATE_RETURN))
THEN
RAISE_APPLICATION_ERROR(-2099, 'You can only book one car per single customer a day');
IF RentAuto.AUTO_ID = :NEW.AUTO_ID
and
((new.date_rent >= RentAuto.date_return and new.date_rent < RentAuto.date_return)
or (new.date_return > RentAuto.date_rent and new.date_return < RentAuto.date_return))
THEN
RAISE_APPLICATION_ERROR(-2099, 'Car has already been rented by another customer!');
END IF;
END IF;
END;