【问题标题】:VB.net function giving ORA-00911 invalid character errorVB.net 函数给出 ORA-00911 无效字符错误
【发布时间】:2011-11-15 08:06:00
【问题描述】:
 Public Shared Function GetData(ByVal id As Integer) As List(Of SomeClass)
            Dim command As New OracleCommand       
            Dim conn As New OracleConnection(WebConfigurationManager.ConnectionStrings("ConnectionString").ToString)
            Dim param As New OracleParameter
            param.ParameterName = "idnumber"
            param.Value = id
            param.DbType = DbType.Int32
            command.Parameters.Add(param) 

            command.Connection = conn
            command.CommandText = "select VAL1, VAL2, Year from local.proc where id = :idnumber and Year = to_number(to_char(sysdate,’YYYY’))"

            Dim reader As OracleDataReader
            Dim someList As New List(Of SomeClass)

            connection.Open()
            reader = command.ExecuteReader()
            While reader.Read
                Dim someClass As New SomeClass
                someClass.VAL1 = reader("VAL1")
                someClass.VAL2 = reader("VAL2")
                someClass.Year = reader("YEAR")
                someList.Add(someClass)
            End While
            connection.Close()
            Return someList
        End Function

此函数给出 ORA-00911 无效字符错误。我有其他相同风格的方法,这些方法运行正常。请对我哪里出错有任何建议吗?谢谢

【问题讨论】:

  • 您缺少参数:idnumber - 您的实际代码中有它吗?

标签: asp.net vb.net oracle data-access-layer ora-00911


【解决方案1】:

我认为问题在于当年 SQL 语句中的引号错误,即:’YYYY’

改成'YYYY'

换行:

command.CommandText = "select VAL1, VAL2, Year from local.proc where id = :idnumber and Year = to_number(to_char(sysdate,’YYYY’))"

command.CommandText = "select VAL1, VAL2, Year from local.proc where id = :idnumber and Year = to_number(to_char(sysdate,'YYYY'))"

【讨论】:

    【解决方案2】:

    您似乎在使用格式化的撇号。

    to_char(sysdate,’YYYY’
    

    试试改成

    to_char(sysdate,'YYYY'
    

    【讨论】:

      猜你喜欢
      • 2013-02-18
      • 1970-01-01
      • 1970-01-01
      • 2014-05-17
      • 1970-01-01
      • 1970-01-01
      • 2014-09-20
      • 2017-07-22
      • 1970-01-01
      相关资源
      最近更新 更多