ORA-01461: can bind a LONG value only for insert into a LONG column-Occurs when querying

前端 未结 15 1761
野的像风
野的像风 2020-11-30 02:44

When I try to query objects, I end up with following error:

ORA-01461: can bind a LONG value only for insert into a LONG column

Could someo

15条回答
  •  北海茫月
    2020-11-30 03:24

    I had the same problem using PHP and prepared statements on a VARCHAR2 column. My string didn't exceeed the VARCHAR2 size. The problem was that I used -1 as maxlength for binding, but the variable content changed later.

    In example:

    $sMyVariable = '';
    $rParsedQuery = oci_parse($rLink, 'INSERT INTO MyTable (MyVarChar2Column) VALUES (:MYPLACEHOLDER)');
    oci_bind_by_name($rParsedQuery, ':MYPLACEHOLDER', $sMyVariable, -1, SQLT_CHR);
    
    $sMyVariable = 'a';
    oci_execute($rParsedQuery, OCI_DEFAULT);
    $sMyVariable = 'b';
    oci_execute($rParsedQuery, OCI_DEFAULT);
    

    If you replace the -1 with the max column width (i. e. 254) then this code works. With -1 oci_bind_by_param uses the current length of the variable content (in my case 0) as maximum length for this column. This results in ORA-01461 when executing.

提交回复
热议问题