Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing stored procedure in PHP : ORA-01460: unimplemented or unreasonable conversion requested

Executing stored procedure in PHP gives ORA-01460. This is the simplified(original has over 48 input values) code in php:

$proc_sql = "BEGIN CREATE_RECORD(:b1, :b2, :b3, :b4, :b5, :b6); END;";

$bind = array("bind 1", "bind 2", "bind 3", "bind 4", "bind 5", "OUT DUMMY");

$stmt = oci_parse($conn, $proc_sql);

$i = 1;

$outval = "";

foreach($bind as $val){
    $tmp =":b".$i;
    if($i < count($bind)){
        oci_bind_by_name($stmt,$tmp,$val);
    }else{
        oci_bind_by_name($stmt, $tmp, $outval, 512);
    }
    $i++;
}
oci_execute($stmt);

Last line produces the warning. However if I run query directly in SQL Developer:

declare
    re varchar2(512);
begin

CREATE_RECORD('bind 1', 'bind 2', 'bind 3', 'bind 4', 'bind 5', re);
dbms_output.put_line(re);

end;

Insert is completed successfully. It's my first project with PHP & Oracle combination. So I don't know if my php is incorrect or the problem lies elsewhere. Here is OCI8 info from phpinfo():

oci8

OCI8 Support    enabled
OCI8 DTrace Support disabled
OCI8 Version    2.0.8
Oracle Run-time Client Library Version  10.2.0.3.0
Oracle Compile-time Instant Client Version  10.2

Directive                        Local Value             Master Value

oci8.default_prefetch                100                     100
oci8.events                          Off                     Off
oci8.max_persistent                   -1                      -1
oci8.old_oci_close_semantics         Off                     Off
oci8.persistent_timeout               -1                      -1
oci8.ping_interval                    60                      60
oci8.privileged_connect              Off                     Off
oci8.statement_cache_size             20                      20

PHP Version 5.5.17 and Oracle 9i Please, help find out why am I getting this warning. Thank you for reading.

UPDATE

The code below also works:

$proc_sql = "BEGIN CREATE_RECORD('bind 1', 'bind 2', 'bind 3', 'bind 4', 'bind 5', :b6); END;";
$stmt = oci_parse($conn, $proc_sql);
$outval = "";
oci_bind_by_name($stmt, ':b6', $outval, 512);

As I said above, this is simplified version of executing procedure code, in reality I need to bind 48 parameters IN and one OUT parameter. Does it have to do something with statement_cache_size in OCI8 settings ? I've read the docs but can't really understand if it has anything to do with my problem.

like image 399
Cԃաԃ Avatar asked Jul 01 '15 05:07

Cԃաԃ


1 Answers

Please, see this piece of PHP documentation, especially this part:

A bind call tells Oracle which memory address to read data from. For IN binds that address needs to contain valid data when oci_execute() is called. This means that the variable bound must remain in scope until execution. If it doesn't, unexpected results or errors such as "ORA-01460: unimplemented or unreasonable conversion requested" may occur. For OUT binds one symptom is no value being set in the PHP variable.

If I undestand your code well, you use a local variable inside a loop to cycle through your IN parameters, so you do not satisfy the demand to have all the values in scope when you call oci_execute after the cycle is completed.

like image 161
David Komanek Avatar answered Nov 09 '22 03:11

David Komanek