我们可以在一个触发器中使用两个表吗?我有历史表,我需要从两个表中放置数据。
IE。
Guest (Guestno, firstname,lastname,address,city, state, zip.....)
Booking (BookingId, Hotelno, Guestno, datefrom, datefrom)
Boogking history (bookingid,guestno, fristname,lastname, address, city, state, zip, hotelno, datefrom, dateto)
所以我想要创建的触发器是,每当在预订表中更新 datefrom 时,它应该更新 booking_history 表中的所有信息(除了 dateto ....如果没有输入 dateto)
我尝试创建以下内容,但它给出了错误,因为在此未提及来宾表,但我不确定该放在哪里
CREATE OR REPLACE TRIGGER BOOKING_DATETO_UPDATE
AFTER UPDATE OF DATETO ON BOOKING
FOR EACH ROW
BEGIN
INSERT INTO BOOKINGHISTORY
(BOOKINGID, GUETNO, FIRSTNAME, LASTNAME, ADDRESS, CITY, STATE, ZIP, HOTELNO, DATETO, DATFROM)
VALUES (:OLD.bookingid,:OLD.guestno, :OLD.FirstName, :OLD.LastName,
:OLD.Address, :OLD.City, :OLD.State, :OLD.Zip, :OLD,Hotelno, :OLD.Dateto, :OLD.Datefrom);
end;
我得到的错误如下。下面是示例,但所有字段都来自 Guest 表(guestno、firstname、lastname、ADDRESS、CITY、STATE)
错误(9,38):PLS-00049:错误的绑定变量“OLD.FIRSTNAME”