Changed name for Queries-A4 to Queries-A5 since they're queries for assignment A5.

This commit is contained in:
K 2024-09-29 23:00:20 +05:30
parent f30b224e99
commit 0a4c55d09b
Signed by: notkshitij
GPG Key ID: C5B8BC7530F8F43F

View 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;
/
```