Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

literal too long

Status
Not open for further replies.

SirCharles

Programmer
Jun 10, 2002
212
0
0
US
In trying to insert a char string >4000 chars to a database field I get 'literal too long' error. How to code for this?

I happen to be using php to fetch values from an html form which includes textarea ( for large text field ).

I tried a normal insert statement, then spent a while looking at a php site and experimentation to come up with following snipet. This piece of code works ok for smaller strings (in comment field), but I still get the error 'literal too long' when trying to insert large value. ie. when value of var > 4000 chars. Any ideas would be helpful.

<snip code>
print &quot;1.&quot;;
$query = &quot;insert into foo
(FIRSTNAME, LASTNAME, COMMENTS)
values
('$firstName', '$lastName', to_clob('$comments'))
returning COMMENTS into :comments&quot;;

print &quot;2.&quot;;

$stmt = @OCIParse($connected, $query);
if($error = OCIError()) {
die(&quot;<font color=red>ERROR!! Syntax error! $error[message]</font>&quot;);
}

$clob1 = OCINewDescriptor($connected, OCI_D_LOB);
if($error = OCIError()) {
die(&quot;<font color=red>ERROR!! Syntax error! $error[message]</font>&quot;);
}
OCIBindByName ($stmt, &quot;:comments&quot;, &$clob1, -1, OCI_B_CLOB);

if($error = OCIError()) {
die(&quot;<font color=red>ERROR!! Syntax error! $error[message]</font>&quot;);
}

print &quot;3.&quot;;

@OCIExecute($stmt);
if($error = OCIError($stmt)) {
die(&quot;<font color=red>ERROR!! Could not execute! $error[message] </font>&quot;
);
}

</snip code>
 
Dude:

I don't understand any code but could it be that you're trying to insert those chars into a column that cannot contain that many?

A varchar2(25) column, for example, will only allow 25 alphanumerics. Maybe the datatype on the column is wrong.

rev
 
The workaround is using concatenation (works for <32K)

Regards, Dima
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top