There is a simple movie schedule table in the cinema:
CREATE TABLE seance ( start_time DATE NOT NULL, -- дата начала фильма (с точностью до минут) films_id_film NUMBER(30) NOT NULL, -- идшник фильма, который будет идти cinema_hall_id_hall NUMBER(30) NOT NULL -- идшник зала, в котором будет идти final_time DATE NOT NULL -- дата окончания фильма (с точностью до минут) ); ALTER TABLE seance ADD CONSTRAINT seance_pk PRIMARY KEY ( cinema_hall_id_hall, films_id_film, start_time, final_time ); Task : to write a trigger that does not allow specifying different films in intersecting periods of time and in the same room . That is, if a film with films_id_film = 1 is 01/01/1999 13:00 - 15:00 in the hall with cinema_hall_id_hall = 1, then you cannot insert the film into the table with the same ID of the hall, whose start date will be 01.01. 1999 2:00 p.m. Thanks in advance for your help! Attempts to solve: there are attempts to solve, but all this does not work. Here is an attempt:
CREATE OR REPLACE TRIGGER check_seance AFTER INSERT OR UPDATE ON SEANCE FOR EACH ROW DECLARE realFinalDate DATE; BEGIN SELECT final_time INTO realFinalDate FROM SEANCE WHERE films_id_film = :new.films_id_film AND cinema_hall_id_hall = :new.cinema_hall_id_hall AND trunc(start_time) = trunc(:new.start_time) AND start_time <> :new.start_time; IF realfinaldate > :new.start_time THEN raise_application_error(-20000, 'Добавление фильма в тот же зал в то же время недопустимо!!!'); END IF; END; /