Oracle vb.net选择参数dbnull.value

时间:2017-06-27 01:23:22

标签: sql vb.net oracle

这有效:

 Dim stSQL as String = "Select ID From Table Where COL Is Null"
 Dim cmd As New OracleCommand
 cmd.Connection = ...
 cmd.CommandText = stSQL
 cmd.BindByName = True

    Try
        Dim oRet As Object = cmd.ExecuteScalar

        If oRet IsNot Nothing Then
            If oRet > 0 Then
                ...
           End If
        End If
    Catch ex As Exception
        Throw ex
    End Try

如果我更改sql字符串以使用参数:

Dim stSQL as String = "Select ID From Table Where COL = :COL"

and add:

cmd.Parameters.Add(New OracleParameter("COL", DBNull.Value))

它不起作用...(oRet = Nothing)有什么想法吗? -Thanks。

Oracle 12c,VS2017,Oracle.DataAccess v4.112.3.0

1 个答案:

答案 0 :(得分:0)

NULL表示"未定义",您无法进行相等的比较。通过= NULL进行比较的任何内容都会返回false。

您必须使用WHERE COL IS NULL