嗨,我有以下脚本
CREATE OR REPLACE TRIGGER DOUBLE_BOOKINGS
BEFORE INSERT OR UPDATE ON BOOKING_SESSION
FOR EACH ROW
DECLARE
session_date TIMESTAMP;
session_room NUMBER;
BEGIN
SELECT start_session
INTO session_date --- EXISTING SESSION
FROM booking_session
WHERE bk_room = :NEW.bk_room;
IF session_date = :NEW.start_session THEN
RAISE_APPLICATION_ERROR
(-1000, 'Room is already booked');
END IF;
END;
/
该脚本假设将任何新预订与同一房间和同一日期的现有预订相匹配(以停止重复预订)
但是它不能正常工作。
SQL> INSERT INTO BOOKING_SESSION VALUES (45,TO_TIMESTAMP('18/03/2012 10:00', '
INSERT INTO BOOKING_SESSION VALUES (45,TO_TIMESTAMP('18/03/2012 10:00', 'DD/MM
*
ERROR at line 1:
ORA-04098: trigger 'U1146815.ROOM_BOOKED' is invalid and failed re-validation
这start_session
是我存储预订日期和时间的数据库列名称,并且是时间戳。是booking_session
保存预订的名称,bk_room
包含房间号。
因此,在提交预订之前,我试图将new
预订日期与同一房间的旧预订日期相匹配,然后显示错误消息。
更新
新错误,似乎返回了太多行我怎么能一次做一个。
ERROR at line 1:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "U1146815.DOUBLE_BOOKINGS", line 5
ORA-04088: error during execution of trigger 'U1146815.DOUBLE_BOOKINGS'