我有这个 ORA 存储过程:
procedure calc(code in number, extLoan in number, loan in number, payment in number, duration in number, saleId in number, resultBlob out clob);
(目前只有这个标题可用)。
我已经尝试过这个 PHP 调用(我oci_*
直接使用函数,尽管我们为它们提供了一个包装器对象):
$query = '
BEGIN
calc(
:code,
:extLoan,
:loan,
:payment,
:duration,
:saleId,
:result);
END;';
$stmt = oci_parse($this->connection, $query);
oci_bind_by_name($stmt, ':code', 100, 3, SQLT_INT);
oci_bind_by_name($stmt, ':extLoan', 20000, 9, SQLT_INT);
oci_bind_by_name($stmt, ':loan', 50000, 9, SQLT_INT);
oci_bind_by_name($stmt, ':payment', 0, 9, SQLT_INT);
oci_bind_by_name($stmt, ':duration', 60, 3, SQLT_INT);
oci_bind_by_name($stmt, ':saleId', 2211445, 9, SQLT_INT); // <- this row is generating the error
// also tried these binds with no luck (same error)
//oci_bind_by_name($stmt, ':code', 100);
//oci_bind_by_name($stmt, ':extLoan', 20000);
//oci_bind_by_name($stmt, ':loan', 50000);
//oci_bind_by_name($stmt, ':payment', 0);
//oci_bind_by_name($stmt, ':duration', 60);
//oci_bind_by_name($stmt, ':saleId', 2211445);
$desc = oci_new_descriptor($this->connection, OCI_D_LOB);
oci_bind_by_name($stmt, ':result', $desc, -1, OCI_B_CLOB);
oci_execute($stmt, OCI_DEFAULT); // <- here the error occurs...
现在,如您所见,所有SQLT_INT
绑定都是纯整数。该过程还等待数字进入......但ORA-01722 invalid number
发生错误。
现在如果我改变
oci_bind_by_name($stmt, ':saleId', 2211445, 9, SQLT_INT);
至
oci_bind_by_name($stmt, ':saleId', 2211445, 9, SQLT_NUM);
执行产生另一个错误:ORA-01403 no data found
。
我最终尝试的是这个电话:
$query = '
BEGIN
calc(
100,
20000,
50000,
0,
60,
2211445,
:result);
END;';
$stmt = oci_parse($this->connection, $query);
$desc = oci_new_descriptor($this->connection, OCI_D_LOB);
oci_bind_by_name($stmt, ':result', $desc, -1, OCI_B_CLOB);
oci_execute($stmt, OCI_DEFAULT); // <- here the error occurs...
但我仍然得到同样的ORA-01722 invalid number
错误。
我还尝试直接在以下位置运行查询sql developer
:
DECLARE
code NUMBER := 100;
extLoan NUMBER := 20000;
loan NUMBER := 50000;
payment NUMBER := 0;
duration NUMBER := 60;
saleId NUMBER := 2211445;
cclob CLOB;
BEGIN
calc(
code,
extLoan,
loan,
payment,
duration,
saleId,
cclob);
dbms_output.put_line(cclob);
END;
并且该语句已成功执行,而输出按预期输出。
您知道可能导致问题的原因吗???
编辑 1:有趣的是,如果我在SQL developer
saleId VARCHAR2(7) := '2211445';
(而不是之前的saleId NUMBER := 2211445;
)该过程仍然没有错误地执行,转换/转换成功......
编辑2:
为确保问题不在于描述符或CLOB
变量绑定,我尝试了下一个调用(其余相同):
$this->db->parseQuery('
DECLARE
code NUMBER := :code;
extloan NUMBER := :extloan;
loan NUMBER := :loan;
payment NUMBER := :payment;
duration NUMBER := :duration;
saleId NUMBER := :saleid;
myclob CLOB;
BEGIN
calc(
code,
extloan,
loan,
payment,
duration,
saleId,
myclob);
:myclob := myclob;
EXCEPTION WHEN OTHERS THEN
:myclob := \'<params>
<code>\' || code || \'</code>
<extloan>\' || extloan || \'</extloan>
<loan>\' || loan || \'</loan>
<payment>\' || payment || \'</payment>
<duration>\' || duration || \'</duration>
<saleId>\' || saleId || \'</saleId>
</params>\';
END;');
删除了绑定,但绑定CLOB
和输出 ( $lob->load();
)返回了正确的 XML 字符串,其中包含传入的所有值...
我想现在很明显问题出在其他地方并且描述符/ clob 绑定是可以的......