Made changed to data inserted in table. Added another exception and changed outputs to be more polite.
This commit is contained in:
parent
ceabc021bd
commit
4d878d51ca
@ -1,7 +1,6 @@
|
|||||||
# P4 - PL/SQL block
|
# P4 - PL/SQL block
|
||||||
|
|
||||||
**Problem Statement:**
|
**Problem Statement:** Write a PL/SQL block for following requirements and handle the exceptions. Roll no. of students will be entered by the user. Attendance of roll no. entered by user will be checked in the Stud table. If attendance is less than 75% then display the message “Term not granted” and set the status in stud table as “Detained”. Otherwise display message “Term granted” and set the status in stud table as “Not Detained”. Student (Roll, Name, Attendance, Status)
|
||||||
Write a PL/SQL block for following requirements and handle the exceptions. Roll no. of students will be entered by the user. Attendance of roll no. entered by user will be checked in the Stud table. If attendance is less than 75% then display the message “Term not granted” and set the status in stud table as “Detained”. Otherwise display message “Term granted” and set the status in stud table as “Not Detained”. Student (Roll, Name, Attendance, Status)
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -20,11 +19,11 @@ CREATE TABLE Student(
|
|||||||
## Inserting data
|
## Inserting data
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
INSERT INTO Student VALUES (1, 'Tanmay', 76, 'Not Yet Reviewed');
|
INSERT INTO Student VALUES (1, 'Tanmay', 76, NULL);
|
||||||
INSERT INTO Student VALUES (2, 'Rajesh', 80, 'Not Yet Reviewed');
|
INSERT INTO Student VALUES (2, 'Rajesh', 80, NULL);
|
||||||
INSERT INTO Student VALUES (3, 'Tejas', 88, 'Not Yet Reviewed');
|
INSERT INTO Student VALUES (3, 'Tejas', 88, NULL);
|
||||||
INSERT INTO Student VALUES (4, 'Machkar', 35, 'Not Yet Reviewed');
|
INSERT INTO Student VALUES (4, 'Machkar', 35, NULL);
|
||||||
INSERT INTO Student VALUES (5, 'Jayashree', 74, 'Not Yet Reviewed');
|
INSERT INTO Student VALUES (5, 'Jayashree', 74, NULL);
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -36,6 +35,7 @@ DECLARE
|
|||||||
p_roll Student.Roll%type;
|
p_roll Student.Roll%type;
|
||||||
nodata EXCEPTION;
|
nodata EXCEPTION;
|
||||||
BEGIN
|
BEGIN
|
||||||
|
DBMS_OUTPUT.PUT_LINE('Enter roll number: ');
|
||||||
p_roll := &p_roll;
|
p_roll := &p_roll;
|
||||||
|
|
||||||
IF (p_roll < 0) THEN
|
IF (p_roll < 0) THEN
|
||||||
@ -45,15 +45,17 @@ BEGIN
|
|||||||
SELECT Attendance INTO p_att FROM Student WHERE Roll = p_roll;
|
SELECT Attendance INTO p_att FROM Student WHERE Roll = p_roll;
|
||||||
|
|
||||||
IF (p_att < 75) THEN
|
IF (p_att < 75) THEN
|
||||||
DBMS_OUTPUT.PUT_LINE('Term not granted!');
|
DBMS_OUTPUT.PUT_LINE('Term not granted to roll no. ' || p_roll);
|
||||||
UPDATE Student SET Status = 'Detained' WHERE Roll = p_roll;
|
UPDATE Student SET Status = 'Detained' WHERE Roll = p_roll;
|
||||||
ELSIF (p_att >= 75) THEN
|
ELSIF (p_att >= 75) THEN
|
||||||
DBMS_OUTPUT.PUT_LINE('Term granted!');
|
DBMS_OUTPUT.PUT_LINE('Term granted to roll no. ' || p_roll);
|
||||||
UPDATE Student SET Status = 'Not Detained' WHERE Roll = p_roll;
|
UPDATE Student SET Status = 'Not Detained' WHERE Roll = p_roll;
|
||||||
END IF;
|
END IF;
|
||||||
EXCEPTION
|
EXCEPTION
|
||||||
WHEN nodata THEN
|
WHEN nodata THEN
|
||||||
DBMS_OUTPUT.PUT_LINE('Enter valid rollno!!');
|
DBMS_OUTPUT.PUT_LINE('Please enter a valid roll number.');
|
||||||
|
WHEN OTHERS THEN
|
||||||
|
DBMS_OUTPUT.PUT_LINE('Error occured. Error: ' SQLERRM);
|
||||||
END;
|
END;
|
||||||
/
|
/
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user