Question: I can not run my SQL codes please give me a fix of my code, then provide the correct SQL code and run screenshots!!!!! here

I can not run my SQL codes please give me a fix of my code, then provide the correct SQL code and run screenshots!!!!!

I can not run my SQL codes please give me a fixhere are my all SQL codes:

/* Create a sequence to generate transaction ids */ CREATE SEQUENCE transaction_seq START WITH 1 INCREMENT BY 1;

/* Procedure to issue a book to a patron */ CREATE OR REPLACE PROCEDURE issueBook(patron_id IN NUMBER, book_id IN NUMBER) AS BEGIN /* Verify patron_id exists in patrons table */ IF NOT EXISTS (SELECT * FROM patrons WHERE patron_id = patron_id) THEN RAISE_APPLICATION_ERROR(-20001, 'Patron does not exist.'); END IF;

/* Verify book_id exists in books table and is not a reference book */ IF NOT EXISTS (SELECT * FROM books WHERE book_id = book_id AND type 'Reference') THEN RAISE_APPLICATION_ERROR(-20002, 'Book does not exist or is a reference book.'); END IF;

/* Insert new row into transactions table */ INSERT INTO transactions (transaction_id, patron_id, book_id, transaction_date, fine, rating) VALUES (transaction_seq.NEXTVAL, patron_id, book_id, SYSDATE, 0, 1); END; /

/* Procedure to calculate the fine due on a returned book */ CREATE OR REPLACE PROCEDURE returnBook(patron_id IN NUMBER, book_id IN NUMBER) AS /* Declare variables to hold fine amount and transaction date */ fine_amount NUMBER; trans_date DATE;

BEGIN /* Retrieve transaction date for the given patron_id and book_id with type = 1 */ SELECT transaction_date INTO trans_date FROM transactions WHERE patron_id = patron_id AND book_id = book_id AND transaction_type = 1;

/* Calculate fine amount if transaction date + 1 month + 7 days is less than current date */ IF SYSDATE > ADD_MONTHS(trans_date, 1) + 7 THEN fine_amount := (SYSDATE - (ADD_MONTHS(trans_date, 1) + 7)) * 0.1; ELSE fine_amount := 0; END IF;

/* Insert new row into transactions table with calculated fine amount and rating of 2 */ INSERT INTO transactions (transaction_id, patron_id, book_id, transaction_date, fine, rating) VALUES (transaction_seq.NEXTVAL, patron_id, book_id, SYSDATE, fine_amount, 2);

/* Print out the calculated fine amount */ DBMS_OUTPUT.PUT_LINE('Fine Amount: ' || fine_amount);

END; /

/* Function to calculate and return the fine due on a returned book */ CREATE OR REPLACE FUNCTION calculateFine(patron_id IN NUMBER, book_id IN NUMBER) RETURN NUMBER AS /* Declare variables to hold fine amount and transaction date */ fine_amount NUMBER; trans_date DATE;

BEGIN /* Retrieve transaction date for the given patron_id and book_id with type = 1 */ SELECT transaction_date INTO trans_date FROM transactions WHERE patron_id = patron_id AND book_id = book_id AND transaction_type = 1;

/* Calculate fine amount if transaction date + 1 month + 7 days is less than current date */ IF SYSDATE > ADD_MONTHS(trans_date, 1) + 7 THEN fine_amount := (SYSDATE - (ADD_MONTHS(trans_date, 1) + 7)) * 0.1; ELSE fine_amount := 0; END IF;

/* Return the calculated fine amount */ RETURN fine_amount;

END; /

/* Procedure to display details of all books issued in February */ CREATE OR REPLACE PROCEDURE displayIssueBooksFeb AS BEGIN /* Select all transactions with type = 1 and transaction date in February */ SELECT b.title, b.author, t.patron_id, t.transaction_date FROM transactions t JOIN books b ON t.book_id = b.book_id WHERE t.transaction_type = 1 AND EXTRACT(MONTH FROM t.transaction_date) = 2;

END;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!