I have written a PL/SQL (Ora10gR2) package which contains a stored procedure. The header looks like this:
procedure updateAddress(
sid in varchar2,
addID in out number,
roomNo in varchar2,
poBox in varchar2,
add1 in varchar2,
add2 in varchar2,
add3 in varchar2,
add4 in varchar2,
add5 in varchar2,
postCode in varchar2,
country in varchar2,
phone1 in varchar2,
phone2 in varchar2,
success out number
);
The purpose of this procedure is to update/append addresses in the database. If addID is null, it inserts and sets addID to the newly inserted address ID; if addID is not null, it just updates (I haven’t written this bit, yet)… Anyway, simple enough.
Calling this procedure works absolutely fine from within SQL Developer. For example, the following works perfectly:
set serveroutput on;
declare
addID number;
status number;
begin
addID := null;
mypackage.updateaddress('XXX11341976', addID, null, null, 'somewhere', 'else', 'NCx 1234', 'UA', null, null, null, null, null, status);
dbms_output.put_line('Status ' || status || ' - New ID ' || addID);
end;
/
It outputs something like Status 20 - New ID 3, where 20 is my all OK code and if I query the address table, the new address is sitting there as ID 3.
However, when I call this code from a PHP script, which uses OCI8, I get an ORA-06502 error:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 1
I know this error usually indicates that you’re trying to fit too much data into some type; for example, putting 999 into number(2), etc. However, this isn’t the case with my SP: there are no limits imposed on the types and, like I say, it works fine in SQL Developer. Likewise, I’m not using dbms_output anywhere in the SP.
This also occurs when I hardcode the PHP script to exactly the same parameters as the above PL/SQL block, or even if I completely remove the body of the procedure and replace it with success := 20. The latter leads me to believe that there’s some problem with the OCI call through PHP, rather than my PL/SQL package. However, I haven’t got a clue what it might be! I’m using this code elsewhere with, admittedly, simpler procedures, and it works fine.
Any ideas what the source might be, or what I can look for? It’s driving me slightly mad!
OK: I found the problem!…
Turns out that my Oracle library code had neglected to set the
maxlengthproperty when it bound variables. I set this to 32767 and, lo and behold, it works!!