Compare commits
4 Commits
f30b224e99
...
da3ef56abb
Author | SHA1 | Date | |
---|---|---|---|
da3ef56abb | |||
50fdaff468 | |||
d3d7cf5c8e | |||
0a4c55d09b |
@ -1,75 +1,91 @@
|
|||||||
## Creating tables & inserting data
|
## Creating tables
|
||||||
|
|
||||||
Student marks:
|
|
||||||
```sql
|
```sql
|
||||||
CREATE TABLE Stud_Marks(
|
CREATE TABLE Borrower (
|
||||||
Roll NUMBER(14),
|
Roll_no NUMBER(15),
|
||||||
name VARCHAR(255),
|
Name VARCHAR(255),
|
||||||
total_marks NUMBER(14),
|
DateOfIssue DATE,
|
||||||
PRIMARY KEY(Roll)
|
NameOfBook VARCHAR(255),
|
||||||
|
Status VARCHAR(255),
|
||||||
|
PRIMARY KEY(Roll_no)
|
||||||
);
|
);
|
||||||
|
|
||||||
INSERT INTO Stud_Marks VALUES (1, 'Arora', 1350);
|
CREATE TABLE Fine (
|
||||||
INSERT INTO Stud_Marks VALUES (2, 'Shankar', 979);
|
Roll_no NUMBER(15),
|
||||||
INSERT INTO Stud_Marks VALUES (3, 'Lara', 834);
|
DateOfReturn DATE,
|
||||||
INSERT INTO Stud_Marks VALUES (4, 'Jambo', 667);
|
Amount NUMBER(15),
|
||||||
INSERT INTO Stud_Marks VALUES (5, 'Tinde', 1400);
|
FOREIGN KEY(Roll_no) REFERENCES Borrower(Roll_no)
|
||||||
|
);
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Result:
|
## Inserting data
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
CREATE TABLE Result(
|
INSERT INTO Borrower (Roll_no, Name, DateOfIssue, NameOfBook, Status) values (1, 'Ayush Kalaskar', TO_DATE('2024-07-28','YYYY-MM-DD'), 'DBMS', 'I');
|
||||||
Roll NUMBER(14),
|
|
||||||
name VARCHAR(255),
|
INSERT INTO Borrower (Roll_no, Name, DateOfIssue, NameOfBook, Status) values (2, 'Himanshu Patil', TO_DATE('2024-07-01','YYYY-MM-DD'),'IOT', 'I');
|
||||||
Class VARCHAR(255),
|
|
||||||
FOREIGN KEY (Roll) REFERENCES Stud_Marks (Roll)
|
INSERT INTO Borrower (Roll_no, Name, DateOfIssue, NameOfBook, Status) values (3, 'Kshitij', TO_DATE('2024-08-05','YYYY-MM-DD'), 'TOC', 'I');
|
||||||
);
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Procedure
|
## Procedure
|
||||||
```sql
|
```sql
|
||||||
CREATE OR REPLACE PROCEDURE proc_grade
|
|
||||||
(rollno in number,
|
|
||||||
p_roll_no out Stud_Marks.Roll%type,
|
|
||||||
p_name out Stud_Marks.name%type,
|
|
||||||
p_total out Stud_Marks.total_marks%type)
|
|
||||||
AS
|
|
||||||
BEGIN
|
|
||||||
SELECT Roll, name, total_marks into p_roll_no, p_name, p_total from Stud_Marks WHERE Roll = rollno;
|
|
||||||
IF p_total <= 1500 and p_total >= 990
|
|
||||||
THEN
|
|
||||||
INSERT INTO Result VALUES (p_roll_no, p_name, 'Distinction');
|
|
||||||
ELSE IF p_total <= 989 and p_total >= 900
|
|
||||||
THEN
|
|
||||||
INSERT INTO Result VALUES (p_roll_no, p_name, 'First Class');
|
|
||||||
ELSE IF p_total <= 899 and p_total >= 825
|
|
||||||
THEN
|
|
||||||
INSERT INTO Result VALUES (p_roll_no, p_name, 'Higher Second Class');
|
|
||||||
ELSE
|
|
||||||
INSERT INTO Result VALUES (p_roll_no, p_name, 'FAIL');
|
|
||||||
END IF;
|
|
||||||
END IF;
|
|
||||||
END IF;
|
|
||||||
EXCEPTION
|
|
||||||
WHEN no_data_found THEN
|
|
||||||
dbms_output.put_line('Rollno ' || rollno || ' is not present!!');
|
|
||||||
END;
|
|
||||||
/
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
## Calling Procedure:
|
|
||||||
```sql
|
|
||||||
DECLARE
|
DECLARE
|
||||||
rollno number(14);
|
p_nameofbook VARCHAR(255);
|
||||||
p_roll_no Stud_Marks.Roll%type;
|
p_rollno NUMBER(15) := 1;
|
||||||
p_name Stud_Marks.name%type;
|
p_dateofissue DATE;
|
||||||
p_total_marks Stud_Marks.total_marks%type;
|
currentdate DATE;
|
||||||
|
noofdays NUMBER(15);
|
||||||
|
amount NUMBER(15);
|
||||||
|
nodata EXCEPTION;
|
||||||
|
|
||||||
BEGIN
|
BEGIN
|
||||||
rollno := &rollno;
|
p_nameofbook := '&p_nameofbook';
|
||||||
proc_grade(rollno, p_roll_no, p_name, p_total_marks);
|
currentdate := SYSDATE;
|
||||||
|
|
||||||
|
IF p_rollno <= 0 THEN
|
||||||
|
RAISE nodata;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
SELECT DateOfIssue
|
||||||
|
INTO p_dateofissue
|
||||||
|
FROM Borrower
|
||||||
|
WHERE Roll_no = p_rollno AND NameOfBook = p_nameofbook;
|
||||||
|
|
||||||
|
SELECT TRUNC(SYSDATE) - p_dateofissue
|
||||||
|
INTO noofdays
|
||||||
|
FROM dual;
|
||||||
|
|
||||||
|
DBMS_OUTPUT.PUT_LINE('No of days: ' || noofdays);
|
||||||
|
IF (noofdays > 30) THEN
|
||||||
|
amount := noofdays * 50;
|
||||||
|
ELSIF (noofdays >= 15 AND noofdays <= 30) THEN
|
||||||
|
amount := noofdays * 5;
|
||||||
|
ELSE
|
||||||
|
amount := 0;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF amount > 0 THEN
|
||||||
|
INSERT INTO Fine (Roll_no, DateOfReturn, Amount)
|
||||||
|
VALUES (p_rollno, SYSDATE, amount);
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF amount > 0 THEN
|
||||||
|
UPDATE Borrower
|
||||||
|
SET Status = 'R'
|
||||||
|
WHERE Roll_no = p_rollno;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
EXCEPTION
|
||||||
|
WHEN nodata THEN
|
||||||
|
DBMS_OUTPUT.PUT_LINE('Roll number or book name not found.');
|
||||||
|
WHEN NO_DATA_FOUND THEN
|
||||||
|
DBMS_OUTPUT.PUT_LINE('No entry found for the provided roll number and book name.');
|
||||||
|
WHEN OTHERS THEN
|
||||||
|
DBMS_OUTPUT.PUT_LINE('An error occurred: ' || SQLERRM);
|
||||||
|
|
||||||
END;
|
END;
|
||||||
/
|
/
|
||||||
|
|
||||||
|
76
Practical/Assignment-A4+A5/Queries-A5.md
Executable file
76
Practical/Assignment-A4+A5/Queries-A5.md
Executable file
@ -0,0 +1,76 @@
|
|||||||
|
## Creating tables & inserting data
|
||||||
|
|
||||||
|
Student marks:
|
||||||
|
```sql
|
||||||
|
CREATE TABLE Stud_Marks(
|
||||||
|
Roll NUMBER(14),
|
||||||
|
name VARCHAR(255),
|
||||||
|
total_marks NUMBER(14),
|
||||||
|
PRIMARY KEY(Roll)
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO Stud_Marks VALUES (1, 'Arora', 1350);
|
||||||
|
INSERT INTO Stud_Marks VALUES (2, 'Shankar', 979);
|
||||||
|
INSERT INTO Stud_Marks VALUES (3, 'Lara', 834);
|
||||||
|
INSERT INTO Stud_Marks VALUES (4, 'Jambo', 667);
|
||||||
|
INSERT INTO Stud_Marks VALUES (5, 'Tinde', 1400);
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Result:
|
||||||
|
```sql
|
||||||
|
CREATE TABLE Result(
|
||||||
|
Roll NUMBER(14),
|
||||||
|
name VARCHAR(255),
|
||||||
|
Class VARCHAR(255),
|
||||||
|
FOREIGN KEY (Roll) REFERENCES Stud_Marks (Roll)
|
||||||
|
);
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Procedure
|
||||||
|
```sql
|
||||||
|
CREATE OR REPLACE PROCEDURE proc_grade
|
||||||
|
(rollno in number,
|
||||||
|
p_roll_no out Stud_Marks.Roll%type,
|
||||||
|
p_name out Stud_Marks.name%type,
|
||||||
|
p_total out Stud_Marks.total_marks%type)
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SELECT Roll, name, total_marks into p_roll_no, p_name, p_total from Stud_Marks WHERE Roll = rollno;
|
||||||
|
IF p_total <= 1500 and p_total >= 990
|
||||||
|
THEN
|
||||||
|
INSERT INTO Result VALUES (p_roll_no, p_name, 'Distinction');
|
||||||
|
ELSE IF p_total <= 989 and p_total >= 900
|
||||||
|
THEN
|
||||||
|
INSERT INTO Result VALUES (p_roll_no, p_name, 'First Class');
|
||||||
|
ELSE IF p_total <= 899 and p_total >= 825
|
||||||
|
THEN
|
||||||
|
INSERT INTO Result VALUES (p_roll_no, p_name, 'Higher Second Class');
|
||||||
|
ELSE
|
||||||
|
INSERT INTO Result VALUES (p_roll_no, p_name, 'FAIL');
|
||||||
|
END IF;
|
||||||
|
END IF;
|
||||||
|
END IF;
|
||||||
|
EXCEPTION
|
||||||
|
WHEN no_data_found THEN
|
||||||
|
dbms_output.put_line('Rollno ' || rollno || ' is not present!!');
|
||||||
|
END;
|
||||||
|
/
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Calling Procedure:
|
||||||
|
```sql
|
||||||
|
DECLARE
|
||||||
|
rollno number(14);
|
||||||
|
p_roll_no Stud_Marks.Roll%type;
|
||||||
|
p_name Stud_Marks.name%type;
|
||||||
|
p_total_marks Stud_Marks.total_marks%type;
|
||||||
|
BEGIN
|
||||||
|
rollno := &rollno;
|
||||||
|
proc_grade(rollno, p_roll_no, p_name, p_total_marks);
|
||||||
|
END;
|
||||||
|
/
|
||||||
|
|
||||||
|
```
|
BIN
Practical/Assignment-A4+A5/Softcopy-A4.pdf
Normal file
BIN
Practical/Assignment-A4+A5/Softcopy-A4.pdf
Normal file
Binary file not shown.
@ -16,7 +16,7 @@ A one-stop Git repository for third year SPPU Computer Engineering students foll
|
|||||||
|
|
||||||
### Practical
|
### Practical
|
||||||
|
|
||||||
> Each folder contains **handout**, **write-up** and **database**.
|
> Each folder contains **handout**, **write-up** and **database** and **softcopy** (i.e. copy + output).
|
||||||
|
|
||||||
1. [Assignment-A2](https://git.kska.io/sppu-te-comp-content/DatabaseManagementSystems/src/branch/main/Practical/Assignment-A2)
|
1. [Assignment-A2](https://git.kska.io/sppu-te-comp-content/DatabaseManagementSystems/src/branch/main/Practical/Assignment-A2)
|
||||||
2. [Assignment-A3](https://git.kska.io/sppu-te-comp-content/DatabaseManagementSystems/src/branch/main/Practical/Assignment-A3)
|
2. [Assignment-A3](https://git.kska.io/sppu-te-comp-content/DatabaseManagementSystems/src/branch/main/Practical/Assignment-A3)
|
||||||
|
Loading…
Reference in New Issue
Block a user