Added content.
- Notes - Practical (Databases, Handouts, Queries, Softcopies, Write-ups) - Question Papers - DISCLAIMER file and motto Lastly, updated README file.
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,86 @@
|
||||
# Database Queries for Assignment-A4
|
||||
|
||||
## Creating tables
|
||||
|
||||
```sql
|
||||
CREATE TABLE Borrower (
|
||||
roll_no INT,
|
||||
issuer_name VARCHAR(255),
|
||||
issue_date DATE,
|
||||
book_name VARCHAR(255),
|
||||
status VARCHAR(1),
|
||||
PRIMARY KEY (roll_no)
|
||||
);
|
||||
|
||||
CREATE TABLE Fine (
|
||||
roll_no INT,
|
||||
return_date DATE,
|
||||
amt INT,
|
||||
FOREIGN KEY (roll_no) REFERENCES Borrower (roll_no)
|
||||
);
|
||||
|
||||
```
|
||||
|
||||
## Inserting data
|
||||
|
||||
```sql
|
||||
INSERT INTO Borrower VALUES (1, 'Kalas', TO_DATE('2024-10-19', 'YYYY-MM-DD'), 'DBMS', 'I');
|
||||
INSERT INTO Borrower VALUES (2, 'Himanshu', TO_DATE('2024-10-01', 'YYYY-MM-DD'), 'TOC', 'I');
|
||||
INSERT INTO Borrower VALUES (3, 'MEPA', TO_DATE('2024-10-25', 'YYYY-MM-DD'), 'IoT', 'I');
|
||||
INSERT INTO Borrower VALUES (4, 'Kshitij', TO_DATE('2024-10-29', 'YYYY-MM-DD'), '1984', 'I');
|
||||
|
||||
```
|
||||
|
||||
## Procedure
|
||||
|
||||
```sql
|
||||
DECLARE
|
||||
p_roll NUMBER; -- specify roll number here since Live SQL cannot take input from user
|
||||
-- Eg. p_roll NUMBER := 1; will take roll number 1 as input
|
||||
p_book VARCHAR2(255); -- specify book name here since Live SQL cannot take input from user
|
||||
-- Eg. p_book VARCHAR2(255) := 'DBMS';
|
||||
p_issueDate DATE;
|
||||
totalDays NUMBER;
|
||||
currentDate DATE;
|
||||
fineAmt NUMBER;
|
||||
nodata EXCEPTION;
|
||||
|
||||
BEGIN
|
||||
-- Check if roll number is valid
|
||||
IF (p_roll <= 0) THEN
|
||||
RAISE nodata;
|
||||
END IF;
|
||||
|
||||
-- Storing values from table in variables
|
||||
SELECT issue_date INTO p_issueDate FROM Borrower WHERE roll_no = p_roll AND book_name = p_book;
|
||||
|
||||
-- Getting the total days since book issue
|
||||
SELECT TRUNC(SYSDATE) - p_issueDate INTO totalDays FROM dual;
|
||||
|
||||
-- Calculating fine
|
||||
IF (totalDays > 30) THEN
|
||||
fineAmt := totalDays * 50; -- Rs. 50 per day for total days greater than 30
|
||||
ELSIF (totalDays BETWEEN 15 AND 30) THEN
|
||||
fineAmt := totalDays * 5; -- Rs. 5 per day for total days between 15 and 30
|
||||
ELSE
|
||||
fineAmt := 0;
|
||||
END IF;
|
||||
|
||||
-- Inserting data into Fine table
|
||||
IF fineAmt > 0 THEN
|
||||
DBMS_OUTPUT.PUT_LINE('Roll no. ' || p_roll || ' has been fined Rs. ' || fineAmt || ' for being ' || totalDays || ' days late.');
|
||||
INSERT INTO Fine VALUES (p_roll, SYSDATE, fineAmt);
|
||||
ELSE
|
||||
DBMS_OUTPUT.PUT_LINE('Roll no. ' || p_roll || ' does not have to pay any fine.');
|
||||
END IF;
|
||||
UPDATE Borrower SET status = 'R' WHERE roll_no = p_roll AND book_name = p_book;
|
||||
|
||||
EXCEPTION
|
||||
WHEN nodata THEN
|
||||
DBMS_OUTPUT.PUT_LINE('Roll number' || p_roll || ' not found.');
|
||||
WHEN OTHERS THEN
|
||||
DBMS_OUTPUT.PUT_LINE('An error occured. Error: ' || SQLERRM);
|
||||
|
||||
END;
|
||||
/
|
||||
```
|
||||
@@ -0,0 +1,54 @@
|
||||
# Queries for Assignment-A5
|
||||
|
||||
> [!NOTE]
|
||||
> Problem Statment: Write a PL/SQL code block to calculate the area of a circle for a value of radius varying from 5 to 9. Store the radius and the corresponding values of calculated area in an empty table named areas, consisting of two columns, radius and area.
|
||||
> Note: Instructor will frame the problem statement for writing PL/SQL block in line with above statement.
|
||||
|
||||
## Creating table
|
||||
|
||||
```sql
|
||||
CREATE TABLE areas (
|
||||
radius INT NOT NULL,
|
||||
area INT
|
||||
);
|
||||
|
||||
```
|
||||
|
||||
## Procedure
|
||||
|
||||
```sql
|
||||
DECLARE
|
||||
v_radius NUMBER; -- specify radius here since Live SQL cannot take input from user
|
||||
-- Eg. v_radius NUMBER := 5 will take radius 5 as input
|
||||
calcedArea NUMBER;
|
||||
invalidData EXCEPTION;
|
||||
psError EXCEPTION;
|
||||
|
||||
BEGIN
|
||||
-- if radius is less than 0, raise exception
|
||||
IF (v_radius < 0) THEN
|
||||
RAISE invalidData;
|
||||
ELSIF (v_radius NOT BETWEEN 5 AND 9) THEN
|
||||
RAISE psError;
|
||||
END IF;
|
||||
|
||||
-- calc area
|
||||
calcedArea := 3.14 * v_radius * v_radius;
|
||||
DBMS_OUTPUT.PUT_LINE('For radius ' || v_radius || ' cm, the area is ' || calcedArea || ' sq. cm.');
|
||||
|
||||
-- add data to table
|
||||
INSERT INTO areas VALUES (v_radius, calcedArea);
|
||||
DBMS_OUTPUT.PUT_LINE('Inserted values to areas database.');
|
||||
|
||||
EXCEPTION
|
||||
WHEN invalidData THEN
|
||||
DBMS_OUTPUT.PUT_LINE('Radius cannot be less than 0 cms. Please enter a valid value.');
|
||||
WHEN psError THEN
|
||||
DBMS_OUTPUT.PUT_LINE('Problem statement requires the radius to be between 5 and 9 cms.');
|
||||
WHEN OTHERS THEN
|
||||
DBMS_OUTPUT.PUT_LINE('An error occured. Error: ' || SQLERRM);
|
||||
|
||||
END;
|
||||
/
|
||||
|
||||
```
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user