The code we have for stored procedure is:
Expand|Select|Wrap|Line Numbers
- CREATE OR REPLACE PROCEDURE p_check_lease_date (
- p_lease_id Lease.LeaseID%TYPE,
- p_property_id Lease.PropertyID%TYPE,
- p_room_id Lease.RoomID%TYPE,
- p_start_date Lease.StartDate%TYPE,
- p_end_date Lease.EndDate%TYPE,
- p_error OUT VARCHAR2
- )
- IS
- v_no_of_rooms NUMBER;
- BEGIN
- IF p_start_date > p_end_date
- THEN
- p_error := 'End date cannot be earlier than start date';
- END IF;
- SELECT COUNT (*)
- INTO v_no_of_rooms
- FROM Lease
- WHERE ( ( p_start_date >= Lease.StartDate
- AND p_start_date <
- NVL (Lease.EndDate, SYSDATE)
- )
- OR ( p_start_date <= Lease.StartDate
- AND p_end_date > Lease.StartDate
- )
- )
- AND Lease.RoomID = p_room_id
- AND Lease.PropertyID = p_property_id
- AND Lease.LeaseID != p_lease_id;
- IF v_no_of_rooms > 0
- THEN
- p_error := 'An Overlapping Room Booking Exists for these dates';
- END IF;
- EXCEPTION
- WHEN OTHERS
- THEN
- p_error :=
- 'System Error '
- || SUBSTR (TO_CHAR (SQLCODE) || ' ' || SQLERRM, 1, 100);
- END;
Expand|Select|Wrap|Line Numbers
- CREATE OR REPLACE TRIGGER trg_Double_Lease_Error
- BEFORE INSERT OR UPDATE OF EndDate ON Lease
- FOR EACH ROW
- BEGIN
- call p_check_lease_date(:new.LeaseID);
- END;