I am trying to run a stored procedure however when I run it with an a valid Number it gives me an ORA-01722 error. I checked to make sure that the columns in the where clause where the parameter is used is of NUMBER type. I checked to make sure that the record exists. Note: When I take out c.charges-c.payment the query runs fine.
create procedure patient_InfoNew(vpatientID NUMBER) IS
x VARCHAR2(300);
BEGIN
select a.firstname || a.lastname || ' ' || a.ssn || ' ' || a.streetname || ' ' || a.phonenumber || ' ' || b.servicedate || ' ' || b.servicetype || ' ' || c.charges - c.payment || ' ' || e.name || ' ' || e.insnumber into x
from patient a, patientaccount b, patient_info c, patientinsurance d, insurance e
where a.id = vpatientID AND e.id = d.insuranceid AND a.id = b.id AND a.id = c.id AND a.id = d.id
AND b.servicedate =
(Select MAX(servicedate)
from patientaccount
where id = vpatientID);
DBMS_OUTPUT.PUT_LINE(x);
EXCEPTION
WHEN VALUE_ERROR THEN
DBMS_OUTPUT.PUT_LINE('Error '||SQLCODE||
SUBSTR(SQLERRM,1,80));
WHEN ZERO_DIVIDE THEN
DBMS_OUTPUT.PUT_LINE('Divide by zero');
WHEN OTHERS THEN
IF SQL%NOTFOUND THEN
DBMS_OUTPUT.PUT_LINE('No such record was found');
END IF;
DBMS_OUTPUT.PUT_LINE('Error '||SQLCODE ||
SUBSTR(SQLERRM,1,80));
END;
This is the error I get below:
No such record was found
Error -1722ORA-01722: invalid number
PL/SQL procedure successfully completed.