2024-10-28 13:38:55 +05:30
|
|
|
# Database Queries for Assignment-A6
|
2024-10-06 13:27:51 +05:30
|
|
|
|
2024-10-28 13:38:55 +05:30
|
|
|
## Creating tables & inserting data
|
2024-10-06 13:27:51 +05:30
|
|
|
|
2024-10-28 13:38:55 +05:30
|
|
|
Student marks:
|
2024-10-06 13:27:51 +05:30
|
|
|
```sql
|
2024-10-28 13:38:55 +05:30
|
|
|
CREATE TABLE Stud_Marks(
|
|
|
|
Roll NUMBER(14),
|
|
|
|
name VARCHAR(255),
|
|
|
|
total_marks NUMBER(14),
|
|
|
|
PRIMARY KEY(Roll)
|
2024-10-06 13:27:51 +05:30
|
|
|
|
2024-10-28 13:38:55 +05:30
|
|
|
);
|
2024-10-06 13:27:51 +05:30
|
|
|
|
2024-10-28 13:38:55 +05:30
|
|
|
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);
|
2024-10-06 13:27:51 +05:30
|
|
|
|
|
|
|
```
|
|
|
|
|
2024-10-28 13:38:55 +05:30
|
|
|
Result:
|
2024-10-06 13:27:51 +05:30
|
|
|
```sql
|
2024-10-28 13:38:55 +05:30
|
|
|
CREATE TABLE Result(
|
|
|
|
Roll NUMBER(14),
|
|
|
|
name VARCHAR(255),
|
|
|
|
Class VARCHAR(255),
|
|
|
|
FOREIGN KEY (Roll) REFERENCES Stud_Marks (Roll)
|
|
|
|
);
|
2024-10-06 13:27:51 +05:30
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
## Procedure
|
|
|
|
```sql
|
2024-10-28 13:38:55 +05:30
|
|
|
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
|
2024-10-06 13:27:51 +05:30
|
|
|
BEGIN
|
2024-10-28 13:38:55 +05:30
|
|
|
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!!');
|
2024-10-06 13:27:51 +05:30
|
|
|
END;
|
|
|
|
/
|
|
|
|
|
|
|
|
```
|
|
|
|
|
2024-10-28 13:38:55 +05:30
|
|
|
## Calling Procedure:
|
2024-10-06 13:27:51 +05:30
|
|
|
```sql
|
|
|
|
DECLARE
|
2024-10-28 13:38:55 +05:30
|
|
|
rollno number(14);
|
|
|
|
p_roll_no Stud_Marks.Roll%type;
|
|
|
|
p_name Stud_Marks.name%type;
|
|
|
|
p_total_marks Stud_Marks.total_marks%type;
|
2024-10-06 13:27:51 +05:30
|
|
|
BEGIN
|
2024-10-28 13:38:55 +05:30
|
|
|
rollno := &rollno;
|
|
|
|
proc_grade(rollno, p_roll_no, p_name, p_total_marks);
|
2024-10-06 13:27:51 +05:30
|
|
|
END;
|
|
|
|
/
|
|
|
|
|
|
|
|
```
|