0
 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 无效字符错误。我有其他相同风格的方法,这些方法运行正常。请对我哪里出错有任何建议吗?谢谢

4

2 回答 2

3
于 2011-09-12T12:59:02.093 回答
2

It looks like you are using formatted apostrophes.

to_char(sysdate,’YYYY’

try change it to

to_char(sysdate,'YYYY'
于 2011-09-12T13:00:01.237 回答