From 95bf49482e1302979aa0077300e0577bbcfeb6cf Mon Sep 17 00:00:00 2001 From: Kshitij Date: Thu, 26 Sep 2024 22:36:44 +0530 Subject: [PATCH] Added queries for a4 --- Practical/Assignment-A4+A5/Queries-A4.md | 76 ++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100755 Practical/Assignment-A4+A5/Queries-A4.md diff --git a/Practical/Assignment-A4+A5/Queries-A4.md b/Practical/Assignment-A4+A5/Queries-A4.md new file mode 100755 index 0000000..f5b1900 --- /dev/null +++ b/Practical/Assignment-A4+A5/Queries-A4.md @@ -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; +/ + +```