Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DECLARE
- /*
- Create new cursor.
- We use 'r_date is null' to check for book state
- r_date is null = not returned yet
- r_date is not null = returned already
- */
- CURSOR bk_c IS
- SELECT * FROM borrow
- WHERE r_date IS NULL;
- /* Declare a new record for our cursor */
- bk_rec bk_c%ROWTYPE;
- /* Assuming the current date is 10th of November */
- /* You should use sysdate for real application */
- crnt_date borrow.r_date%TYPE := TO_DATE('10-NOV-18');
- /* Declare member's name and mobile variables */
- mem_name member.name%TYPE;
- mem_mobile member.mobile%TYPE;
- days_since_borrowed NUMBER;
- BEGIN
- /* Open cursor and loop through result */
- OPEN bk_c;
- LOOP
- /* Fetch result into our record */
- FETCH bk_c INTO bk_rec;
- /* Exit loop if no result found */
- EXIT WHEN bk_c%notfound;
- /* Find out member name and mobile */
- SELECT name, mobile INTO mem_name, mem_mobile
- FROM member WHERE m_id = bk_rec.m_id;
- /*
- Calculate how many days since the book borrowed
- By subtracting the borrow date from current date
- Use FLOOR to avoid decimals.
- */
- days_since_borrowed := FLOOR(crnt_date - bk_rec.b_date);
- /* Print result */
- dbms_output.put_line(mem_name || ' ' || mem_mobile ||
- ' has not returned his book since '
- || days_since_borrowed || ' days.');
- END LOOP;
- CLOSE bk_c;
- END;
- /
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement