Home » SQL & PL/SQL » SQL & PL/SQL » ORA-01422: exact fetch returns more than requested number of rows
ORA-01422: exact fetch returns more than requested number of rows [message #20294] Sat, 11 May 2002 16:01 Go to next message
kam
Messages: 3
Registered: May 2002
Junior Member
i have a stored fuction as:

set serveroutput on;

create or replace function totalbill
(i_patientno patient.patientno%type)

return number
is

v_total_bill patient.bill%type;

begin
select ((costperday*noofdays)+cost)
into v_total_bill from

(SELECT T.TREATMENTNO, T.COST, CS.PATIENTNO, R.COSTPERDAY, P.NOOFDAYS
FROM TREATMENT T, CONSULTATION CS, ROOM R, PATIENT P
WHERE T.TREATMENTNO=CS.TREATMENTNO
AND R.ROOMNUMBER=P.ROOMNUMBER AND CS.PATIENTNO=P.PATIENTNO);

if v_total_bill is null then
v_total_bill :=0;
end if;
-- to zero
return v_total_bill;

end;
/

and a stored procedure AS

set serveroutput on;

create or replace procedure calculatebill
as

cursor c_patient
is
select patientno
from patient;

v_total_bill patient.bill%type;
v_patientno patient.patientno%type;

begin
open c_patient;
loop
fetch c_patient into v_patientno;
exit when c_patient%notfound;

v_total_bill := totalbill(v_total_bill);
update patient
set bill = v_total_bill
where patientno=v_patientno;

end loop;
close c_patient;
end;
/

and when i execute the procedure i get the following error:

ERROR at line 1:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "SCOTT.TOTALBILL", line 9
ORA-06512: at "SCOTT.CALCULATEBILL", line 18
ORA-06512: at line 1

anybody that can help it will be gratefull
Re: ORA-01422: exact fetch returns more than requested number of rows [message #20295 is a reply to message #20294] Sat, 11 May 2002 22:49 Go to previous message
Remash
Messages: 52
Registered: November 2000
Member
Take the sum. ie.
select sum((costperday*noofdays)+cost) into .....
Previous Topic: Identification of foreign key
Next Topic: ORA-01422, ORA-06512
Goto Forum:
  


Current Time: Thu Apr 25 14:16:24 CDT 2024