2

I am trying to update an Oracle Database record and i keep getting this error:

ORA-01704: string literal too long 5

I looked up that error and it seems that i have a limit of 4000 charters since i am using Oracle 10g. However, the prgblem is that its the same exact data i am putting back into that record so that is why i am unsure as to why its giving me that error for the same amount of data i took out of it.

Here is my update code:

    Dim myCommand As New OracleCommand()
    Dim ra As Integer

    Try
        myCommand = New OracleCommand("Update CSR.CSR_EAI_SOURCE Set STATUS_CODE = 'Blah', COMPLETE_DATE = '', DATA = '" & theData & "' WHERE EID = '81062144'", OracleConnection)
        ra = myCommand.ExecuteNonQuery()
        OracleConnection.Close()
    Catch
        MsgBox("ERROR" & Err.Description & " " & Err.Number)
    End Try

I'm not sure if there is anything special you have to do in order to update a clob or not.

I extract the clob like so:

 Dim blob As OracleClob = dr.GetOracleClob(9)
 Dim theData As String = ""

 theData = blob.Value

And it works just fine extracting but just not putting it back in.

Any help would be great!

David

UPDATE CODE

 Dim OracleCommand As New OracleCommand()
 Dim myCommand As New OracleCommand()
 Dim ra As Integer

 While dr.Read()
    Dim blob As OracleClob = dr.GetOracleClob(9)
    Dim theData As String = ""

    theData = blob.Value
    theData = Replace(theData, "…", " ")

    Try
       Dim strSQL As String
       isConnected2 = connectToOracleDB2()
       OracleConnection.Close()

       If isConnected2 = False Then
           MsgBox("ERRORConn: " & Err.Description & " " & Err.Number)
       Else
           myCommand.Connection = OracleConnection2
           strSQL = "Update CSR.CSR_EAI_SOURCE Set STATUS_CODE = 'ERROR', COMPLETE_DATE = '', DATA = :1 WHERE EID = '" & theEID & "'"
           myCommand.CommandText = strSQL

           Dim param As OracleParameter = myCommand.Parameters.Add("", OracleDbType.Clob)
           param.Direction = ParameterDirection.Input
           param.Value = theData
           Application.DoEvents()

           ra = myCommand.ExecuteNonQuery()
           Application.DoEvents()
           OracleConnection2.Close()
           Application.DoEvents()
       End If
    Catch
       MsgBox("ERROR: " & Err.Description & " " & Err.Number)
       OracleConnection2.Close()
    End Try
 End While

 dr.Close()
 OracleConnection.Close()
4

2 回答 2

1

不要将值硬编码到 SQL 查询中。而是将其包装在参数中。像这样:

Dim strSQL As String
strSQL = "Update CSR.CSR_EAI_SOURCE Set STATUS_CODE = 'Blah', COMPLETE_DATE = '', DATA = :1 WHERE EID = '81062144'"
myCommand.CommandText=strSQL

接着:

Dim param As OracleParameter=myCommand.Parameters.Add("",OracleDbType.Clob)
param.Direction=ParameterDirection.Input
param.Value=blob.Value

当然,您也可以(并且应该)将查询的所有其他变量(状态代码、完整日期、eid)添加为参数,而不是将它们硬编码到 SQL 中。

于 2011-03-17T12:44:52.290 回答
0

sql中的varchar2有4000个字符的限制。此限制不适用于存储在 varchar 列中的数据。您需要将其转换为 pl\sql 或指定其他列类型。(我不是 php 专家。所以我不能提供任何示例,只是你错误的原因)。

本质上,您需要在执行绑定查询时将数据类型指定为 clob。否则它将默认为 varchar2 并且将适用上述限制。

于 2011-03-17T12:21:27.683 回答