Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

Commit

Permalink
add person procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
L23de committed Apr 25, 2022
1 parent e7b0470 commit 5de4106
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions db/procedures/add_person_to_lease.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
CREATE OR REPLACE PROCEDURE add_person_to_lease (
pid IN person.id%type,
lid IN lease.id%type,
success OUT number
) IS
valid number;
BEGIN
-- Check if lease is valid
SELECT COUNT(*) INTO valid
FROM lease join person_on_lease on lease.id = person_on_lease.person_id
WHERE
lease.id = lid AND person_id <> pid AND
CURRENT_TIMESTAMP >= ADD_MONTHS(start_date, term_length);

IF valid <> 0 THEN
success := 1;
return;
END IF;

INSERT INTO person_on_lease VALUES(lid, pid);
success := 0;
END;

0 comments on commit 5de4106

Please sign in to comment.