graziazi
asked on
Cursor functionality limited
Hi. I am trying to implement a cursor that accesses all Medications. If a the amount of a med is less than 70 raise an application error. If any med is greater than 100 output a message then re-raise the exception.
Here's my code.......
When I run my code however, only 1 row is returned 'saying xxxx has a medication less than 70. even though there are other rows with med < 70 and rows > 100
Here's my code.......
DECLARE
med_too_much EXCEPTION;
CURSOR medAmount IS
SELECT * FROM Medication;
v_med medAmount%ROWTYPE;
BEGIN
OPEN medAmount;
FETCH medAmount INTO v_med;
WHILE medAmount%FOUND LOOP
DBMS_OUTPUT.PUT_LINE(v_med.medication || '' || v_med.amount_in_mg || '' || v_med.prescription_id);
FETCH medAmount INTO v_med;
if v_med.amount_in_mg < 70 then
raise_application_error(-20001, v_med.medication || ' with ' || v_med.prescription_id || ' has a medication less than 70 ');
else
if v_med.amount_in_mg > 100 then
RAISE med_too_much;
end if;
end if;
END LOOP;
CLOSE medAmount;
EXCEPTION
WHEN med_too_much THEN
dbms_output.put_line('Is too much');
CLOSE medAmount;
END;
/
When I run my code however, only 1 row is returned 'saying xxxx has a medication less than 70. even though there are other rows with med < 70 and rows > 100
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No need to take it out. Just don't raise an exception unless you 'handle' it.
ASKER