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

前端 未结 15 1753
野的像风
野的像风 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:12

    Kiran's answer is definetely the answer for my case.

    In code part I split string to 4000 char strings and try to put them in to db.

    Explodes with this error.

    The cause of the error is using utf chars, those counts 2 bytes each. Even I truncate to 4000 chars in code(sth. like String.Take(4000)), oracle considers 4001 when string contains 'ö' or any other non-eng(non ascii to be precise, which are represented with two or bytes in utf8) characters.

    0 讨论(0)
  • 2020-11-30 03:13

    It can also happen with varchar2 columns. This is pretty reproducible with PreparedStatements through JDBC by simply

    1. creating a table with a column of varchar2 (20 or any arbitrary length) and
    2. inserting into the above table with a row containing more than 20 characters

    So as above said it can be wrong with types, or column width exceeded.

    Also note that as varchar2 allows 4k chars max, the real limit will be 2k for double byte chars

    Hope this helps

    0 讨论(0)
  • 2020-11-30 03:13

    I had the same problem with Entity Framework database first on all CLOB columns.

    As a workaround, I filled the text values with spaces to be at least 4000 in width in insert operations (did not come with any better solution).

    0 讨论(0)
  • 2020-11-30 03:14

    I encountered the same problem using Siebel REXPIMP (registry import) when using the latest Instant Client driver. To fix the issues, use the Siebel provided Data Direct driver instead. The DLL is SEOR823.DLL

    0 讨论(0)
  • 2020-11-30 03:22

    This error occurs when one attempts to use a varchar variable longer than 4000 bytes in an SQL statement. PL/SQL allows varchars up to 32767 bytes, but the limit for database tables and SQL language is 4000. You can't use PL/SQL variables that SQL doesn't recognize in SQL statements; an exception, as the message explains, is a direct insert into a long-type column.

    create table test (v varchar2(10), c clob);
    
    
    declare
      shortStr varchar2(10) := '0123456789';
      longStr1 varchar2(10000) := shortStr;
      longStr2 varchar2(10000);
    begin
      for i in 1 .. 10000
      loop
        longStr2 := longStr2 || 'X';
      end loop;
    
      -- The following results in ORA-01461
      insert into test(v, c) values(longStr2, longStr2);
    
      -- This is OK; the actual length matters, not the declared one
      insert into test(v, c) values(longStr1, longStr1);
    
      -- This works, too (a direct insert into a clob column)
      insert into test(v, c) values(shortStr, longStr2);
    
      -- ORA-01461 again: You can't use longStr2 in an SQL function!
      insert into test(v, c) values(shortStr, substr(longStr2, 1, 4000));
    end;
    
    0 讨论(0)
  • 2020-11-30 03:24

    A collegue of me and I found out the following:

    When we use the Microsoft .NET Oracle driver to connect to an oracle Database (System.Data.OracleClient.OracleConnection)

    And we are trying to insert a string with a length between 2000 and 4000 characters into an CLOB or NCLOB field using a database-parameter

    oraCommand.CommandText = "INSERT INTO MY_TABLE (NCLOB_COLUMN) VALUES (:PARAMETER1)";
    // Add string-parameters with different lengths
    // oraCommand.Parameters.Add("PARAMETER1", new string(' ', 1900)); // ok
    oraCommand.Parameters.Add("PARAMETER1", new string(' ', 2500));  // Exception
    //oraCommand.Parameters.Add("PARAMETER1", new string(' ', 4100)); // ok
    oraCommand.ExecuteNonQuery();
    
    • any string with a length under 2000 characters will not throw this exception
    • any string with a length of more than 4000 characters will not throw this exception
    • only strings with a length between 2000 and 4000 characters will throw this exception

    We opened a ticket at microsoft for this bug many years ago, but it has still not been fixed.

    0 讨论(0)
提交回复
热议问题