Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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!!!!!

image text in transcribedhere 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 1 Lncs 13426

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124227, 978-3031124228

More Books

Students also viewed these Databases questions