ORA-01722 运行 存储过程时出错
ORA-01722 Error when running stored procedure
我正在尝试 运行 一个存储过程,但是当我 运行 它带有一个有效的数字时,它给我一个 ORA-01722 错误。我检查以确保使用参数的 where 子句中的列是 NUMBER 类型。我检查以确保该记录存在。注意:当我取出 c.charges-c.payment 时,查询 运行 没问题。
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;
这是我在下面得到的错误:
No such record was found
Error -1722ORA-01722: invalid number
PL/SQL procedure successfully completed.
将减法括在括号中:(c.charges - c.payment)
如果你不这样做,你实际上是在尝试减去字符串(减号左侧的所有内容都连接在一起,减号右侧的所有内容连接在一起)。
双方都未计算出有效数字。
有关操作顺序的更多信息,请参见此处:http://docs.oracle.com/cd/B14117_01/appdev.101/b10807/02_funds.htm
注意减法和连接在同一层级,因此您需要括号来阐明表达式的含义。
我正在尝试 运行 一个存储过程,但是当我 运行 它带有一个有效的数字时,它给我一个 ORA-01722 错误。我检查以确保使用参数的 where 子句中的列是 NUMBER 类型。我检查以确保该记录存在。注意:当我取出 c.charges-c.payment 时,查询 运行 没问题。
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;
这是我在下面得到的错误:
No such record was found
Error -1722ORA-01722: invalid number
PL/SQL procedure successfully completed.
将减法括在括号中:(c.charges - c.payment)
如果你不这样做,你实际上是在尝试减去字符串(减号左侧的所有内容都连接在一起,减号右侧的所有内容连接在一起)。
双方都未计算出有效数字。
有关操作顺序的更多信息,请参见此处:http://docs.oracle.com/cd/B14117_01/appdev.101/b10807/02_funds.htm
注意减法和连接在同一层级,因此您需要括号来阐明表达式的含义。