ORA-01461 when trying to insert text > 4000 characters into a CLOB column
758270Mar 5 2010 — edited May 13 2010I work on a Windows application that connects to databases using ODBC. I'm currently working on adding Oracle support to the application, but I'm running into a lot of problems inserting strings of more than 4000 characters into CLOB columns. First, I tried to do that directly using code similar to the following (setup, cleanup, and error checking snipped for clarity).
SQLHDBC hDbc;
SQLHSTMT hStmt;
unsigned char query[200];
SQLAllocStmt(hDbc, &hStmt);
strcpy(query,"INSERT INTO test_table (col_clob, col_int) ('long string', 1)");
SQLExecDirect(hStmt,query,strlen(query));
Of course, "long string" was really a string of more than 4000 characters. When I did that, I got an error indicating that I needed to use bind parameters for strings that long. However, bind parameters don't seem to work either. I changed my code to something like the following:
SQLHDBC hDbc;
SQLHSTMT hStmt;
unsigned char query[200];
+unsigned char *str=NULL;+
int str_size;
SQLAllocStmt(hDbc, &hStmt);
strcpy(query,"INSERT INTO test_table (col_clob, col_int) (:strvar, 1)");
SQLPrepare(hStmt,query,SQL_NTS);
str = (unsigned char*)malloc(6000 * sizeof(unsigned char));
SQLBindParameter(hStmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARBINARY, 0, 0, str, sizeof(str), &str_size);
strcpy(str,'long_string');
str_size = SQL_NTS;
SQLExecute(hStmt);
This code works fine when 'long_string' is less than 4000 characters. When it's greater than that, I get the following error:
+[Oracle][ODBC][Ora]ORA-01461: can bind a LONG value only for insert into a LONG column+
I'm using Visual Studio.NET 2003 on Windows XP, and Oracle client 11.1.0.6.0. My server version is as follows:
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
I thought I read somewhere that this is a known bug with Oracle 10.2.0.1.0, but I can't seem to find the reference now. Can anyone confirm this or provide some assistance with this problem? Frankly, it seems kind of ridiculous that I can't do something as simple as inserting a reasonably sized amount of text into a CLOB column. I'm considering using BFILEs instead, but that would be kind of a pain to fit into our application, so I'd prefer not to do this if at all possible.
Thanks in advance for any help.