2024-10-28 13:38:55 +05:30
|
|
|
# Database Queries for Assignment-A6
|
2024-10-06 13:27:51 +05:30
|
|
|
|
2024-11-02 20:35:43 +05:30
|
|
|
## Creating tables
|
2024-10-06 13:27:51 +05:30
|
|
|
|
|
|
|
```sql
|
2024-11-02 20:35:43 +05:30
|
|
|
CREATE TABLE Stud_Marks (
|
|
|
|
roll INT,
|
|
|
|
name VARCHAR(255),
|
|
|
|
total_marks INT,
|
|
|
|
PRIMARY KEY (roll)
|
2024-10-28 13:38:55 +05:30
|
|
|
);
|
2024-10-06 13:27:51 +05:30
|
|
|
|
2024-11-02 20:35:43 +05:30
|
|
|
CREATE TABLE Result (
|
|
|
|
roll INT,
|
|
|
|
name VARCHAR(255),
|
|
|
|
class VARCHAR(255),
|
|
|
|
FOREIGN KEY (roll) REFERENCES Stud_Marks (roll)
|
|
|
|
);
|
2024-10-06 13:27:51 +05:30
|
|
|
|
|
|
|
```
|
|
|
|
|
2024-11-02 20:35:43 +05:30
|
|
|
## Inserting data
|
|
|
|
|
2024-10-06 13:27:51 +05:30
|
|
|
```sql
|
2024-11-02 20:35:43 +05:30
|
|
|
INSERT INTO Stud_Marks VALUES (1, 'Kshitij', 1400);
|
|
|
|
INSERT INTO Stud_Marks VALUES (2, 'Kalas', 500);
|
|
|
|
INSERT INTO Stud_Marks VALUES (3, 'Himanshu', 995);
|
|
|
|
INSERT INTO Stud_Marks VALUES (4, 'MEPA', 850);
|
|
|
|
INSERT INTO Stud_Marks VALUES (5, 'Macho', 900);
|
2024-10-06 13:27:51 +05:30
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
## Procedure
|
2024-11-02 20:35:43 +05:30
|
|
|
|
2024-10-06 13:27:51 +05:30
|
|
|
```sql
|
2024-11-02 20:35:43 +05:30
|
|
|
CREATE OR REPLACE PROCEDURE proc_Grade (roll_no IN NUMBER) AS
|
|
|
|
|
|
|
|
-- declare section
|
|
|
|
p_roll Stud_Marks.roll%TYPE;
|
|
|
|
p_name Stud_Marks.name%TYPE;
|
|
|
|
p_total NUMBER;
|
|
|
|
|
2024-10-06 13:27:51 +05:30
|
|
|
BEGIN
|
2024-11-02 20:35:43 +05:30
|
|
|
SELECT roll, name, total_marks INTO p_roll, p_name, p_total FROM Stud_Marks WHERE roll = roll_no;
|
|
|
|
|
|
|
|
IF (p_total <= 1500 AND p_total >= 990) THEN
|
|
|
|
INSERT INTO Result VALUES (p_roll, p_name, 'Distinction');
|
|
|
|
DBMS_OUTPUT.PUT_LINE(p_name || ' (roll no. ' || p_roll || ') has been placed in the DISTINCTION category.');
|
|
|
|
ELSIF (p_total BETWEEN 900 AND 989) THEN
|
|
|
|
INSERT INTO Result VALUES (p_roll, p_name, 'First Class');
|
|
|
|
DBMS_OUTPUT.PUT_LINE(p_name || ' (roll no. ' || p_roll || ') has been placed in the FIRST CLASS.');
|
|
|
|
ELSIF (p_total BETWEEN 825 AND 899) THEN
|
|
|
|
INSERT INTO Result VALUES (p_roll, p_name, 'Higher Second Class');
|
|
|
|
DBMS_OUTPUT.PUT_LINE(p_name || ' (roll no. ' || p_roll || ') has been placed in the HIGHER SECOND CLASS.');
|
|
|
|
ELSE
|
|
|
|
INSERT INTO Result VALUES (p_roll, p_name, 'Fail');
|
|
|
|
DBMS_OUTPUT.PUT_LINE(p_name || ' (roll no. ' || p_roll || ') has FAILED.');
|
|
|
|
END IF;
|
|
|
|
|
2024-10-28 13:38:55 +05:30
|
|
|
EXCEPTION
|
2024-11-02 20:35:43 +05:30
|
|
|
WHEN NO_DATA_FOUND THEN
|
|
|
|
DBMS_OUTPUT.PUT_LINE('No entry for this roll number in the Stud_Marks database.');
|
|
|
|
|
|
|
|
END proc_Grade;
|
2024-10-06 13:27:51 +05:30
|
|
|
/
|
|
|
|
|
|
|
|
```
|
|
|
|
|
2024-11-02 20:35:43 +05:30
|
|
|
## Calling procedure
|
|
|
|
|
2024-10-06 13:27:51 +05:30
|
|
|
```sql
|
|
|
|
DECLARE
|
2024-11-02 20:35:43 +05:30
|
|
|
roll_no NUMBER;
|
2024-10-06 13:27:51 +05:30
|
|
|
BEGIN
|
2024-11-02 20:35:43 +05:30
|
|
|
roll_no := &roll_no; -- replace &roll_no with a number for Live SQL since it does not support user input.
|
|
|
|
proc_Grade(roll_no);
|
2024-10-06 13:27:51 +05:30
|
|
|
END;
|
|
|
|
/
|
|
|
|
|
|
|
|
```
|