$$ Trigger with use when condition $$
CREATE OR REPLACE TRIGGER trg_hpms_room
AFTER INSERT OR UPDATE
ON hpms_room
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
WHEN (NEW.occupancy_service IN ('E', 'C', 'D'))
BEGIN
IF INSERTING
THEN
IF :NEW.occupancy_service = 'C'
THEN
DECLARE
sl NUMBER (3);
BEGIN
SELECT MAX (view_sl) + 1
INTO sl
FROM op_patdisplay
WHERE tvdisplay_id = 1;
INSERT INTO op_patdisplay
(room_name, movement_type_no, room_no, view_sl,
show_fg, view_page, tvdisplay_id, check_inout
)
VALUES (:NEW.room_name, '5', :NEW.room_no, sl,
'1', '1', '1', '0'
);
END;
ELSIF :NEW.occupancy_service = 'E'
THEN
DECLARE
sl NUMBER (3);
BEGIN
SELECT MAX (view_sl) + 1
INTO sl
FROM op_patdisplay
WHERE tvdisplay_id = 3;
INSERT INTO op_patdisplay
(room_name, movement_type_no, room_no, view_sl,
show_fg, view_page, tvdisplay_id, check_inout
)
VALUES (:NEW.room_name, '5', :NEW.room_no, sl,
'1', '1', '3', '0'
);
END;
ELSIF :NEW.occupancy_service = 'D'
THEN
DECLARE
sl NUMBER (3);
BEGIN
SELECT MAX (view_sl) + 1
INTO sl
FROM op_patdisplay
WHERE tvdisplay_id = 2;
INSERT INTO op_patdisplay
(room_name, movement_type_no, room_no, view_sl,
show_fg, view_page, tvdisplay_id, check_inout
)
VALUES (:NEW.room_name, '5', :NEW.room_no, sl,
'1', '1', '2', '0'
);
END;
END IF;
END IF;
EXCEPTION
WHEN OTHERS
THEN
NULL;
END;
/
CREATE OR REPLACE TRIGGER trg_hpms_room
AFTER INSERT OR UPDATE
ON hpms_room
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
WHEN (NEW.occupancy_service IN ('E', 'C', 'D'))
BEGIN
IF INSERTING
THEN
IF :NEW.occupancy_service = 'C'
THEN
DECLARE
sl NUMBER (3);
BEGIN
SELECT MAX (view_sl) + 1
INTO sl
FROM op_patdisplay
WHERE tvdisplay_id = 1;
INSERT INTO op_patdisplay
(room_name, movement_type_no, room_no, view_sl,
show_fg, view_page, tvdisplay_id, check_inout
)
VALUES (:NEW.room_name, '5', :NEW.room_no, sl,
'1', '1', '1', '0'
);
END;
ELSIF :NEW.occupancy_service = 'E'
THEN
DECLARE
sl NUMBER (3);
BEGIN
SELECT MAX (view_sl) + 1
INTO sl
FROM op_patdisplay
WHERE tvdisplay_id = 3;
INSERT INTO op_patdisplay
(room_name, movement_type_no, room_no, view_sl,
show_fg, view_page, tvdisplay_id, check_inout
)
VALUES (:NEW.room_name, '5', :NEW.room_no, sl,
'1', '1', '3', '0'
);
END;
ELSIF :NEW.occupancy_service = 'D'
THEN
DECLARE
sl NUMBER (3);
BEGIN
SELECT MAX (view_sl) + 1
INTO sl
FROM op_patdisplay
WHERE tvdisplay_id = 2;
INSERT INTO op_patdisplay
(room_name, movement_type_no, room_no, view_sl,
show_fg, view_page, tvdisplay_id, check_inout
)
VALUES (:NEW.room_name, '5', :NEW.room_no, sl,
'1', '1', '2', '0'
);
END;
END IF;
END IF;
EXCEPTION
WHEN OTHERS
THEN
NULL;
END;
/
0 comments:
Post a Comment