ORA-01008: not all variables bound. They are bound

前端 未结 8 1394
青春惊慌失措
青春惊慌失措 2020-11-29 08:01

I have come across an Oracle problem for which I have so far been unable to find the cause. The query below works in Oracle SQL developer, but when running in .NET it throws

8条回答
  •  执笔经年
    2020-11-29 08:28

    On Charles' comment problem: to make things worse, let

    :p1 = 'TRIALDEV'
    

    via a Command Parameter, then execute

    select T.table_name as NAME, COALESCE(C.comments, '===') as DESCRIPTION
    from all_all_tables T
    Inner Join all_tab_comments C on T.owner = C.owner and T.table_name = C.table_name
    where Upper(T.owner)=:p1
    order by T.table_name
    
    558 line(s) affected. Processing time: 00:00:00.6535711
    

    and when changing the literal string from === to ---

    select T.table_name as NAME, COALESCE(C.comments, '---') as DESCRIPTION
    [...from...same-as-above...]
    
    ORA-01008: not all variables bound
    

    Both statements execute fine in SQL Developer. The shortened code:

                Using con = New OracleConnection(cs)
                    con.Open()
                    Using cmd = con.CreateCommand()
                        cmd.CommandText = cmdText
                        cmd.Parameters.Add(pn, OracleDbType.NVarchar2, 250).Value = p
                        Dim tbl = New DataTable
                        Dim da = New OracleDataAdapter(cmd)
                        da.Fill(tbl)
                        Return tbl
                    End Using
                End Using
    

    using Oracle.ManagedDataAccess.dll Version 4.121.2.0 with the default settings in VS2015 on the .Net 4.61 platform.

    So somewhere in the call chain, there might be a parser that is a bit too aggressively looking for one-line-comments started by -- in the commandText. But even if this would be true, the error message "not all variables bound" is at least misleading.

提交回复
热议问题