'PL/SQL raising a sample grade by 11.5
Hi i need to make a pl/sql procedure where I can raise a sample grade by 11.5, however im confused on how to do this. I finished most of the code but still stuck on raising it by 11.5. Can someone help
--QUESTION Write a procedure called raisemarksXX that will take a sample grade and raise it by 11.5. Do not allow the output to go above 100. Execute it twice. Once with 48 and the second with 92. Answer goes below
my code (I know it is wrong but I'm confused on what to do.)
CREATE OR REPLACE PROCEDURE raisemarksXX
(student_id studXX.sid %type)
AS
newGrade studXX.marks%type;
BEGIN
SELECT SID FROM studXX WHERE MARKS(48)>(SELECT AVG(MARKS(48))FROM studXX);
SELECT SID FROM studXX WHERE MARKS(92)>(SELECT AVG(MARKS(92))FROM studXX);
newGrade:= newGrade + 11.5;
DBMS_OUTPUT.PUT_LINE('sid: ');
DBMS_OUTPUT.PUT_LINE('Marks: ')
DBMS_OUTPUT.PUT_LINE(‘Grade: ’);
END studXX;
/
EXEC studXX(1);
insert statements
insert into studXX ( sid, marks) values (1,80)
insert into studXX ( sid, marks) values (2,90)
insert into studXX ( sid, marks) values (3,70)
insert into studXX ( sid, marks) values (4,67)
insert into studXX ( sid, marks) values (5, 79)
insert into studXX ( sid, marks) values (6,21)
Solution 1:[1]
Ok, I will do part of your homework for you. I would move the calculation to a function:
CREATE OR REPLACE FUNCTION adjustmark (p_current IN NUMBER
, p_adjust IN NUMBER
, p_max in number default 100.
, p_min in number default 0.0)
RETURN NUMBER
AS
l_ret NUMBER;
BEGIN
l_ret := p_current + p_adjust;
l_ret :=
CASE
WHEN l_ret > p_max THEN p_max
WHEN l_ret < p_min THEN p_min
ELSE l_ret
END;
RETURN l_ret;
END adjustmark;
The function allows increases or decreases of any amounts, but limits the results to between 0 and 100. I will leave it to you as to how to incorporate this function in the remainder of the problem.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Brian Leach |
