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无效字符错误。我有其他相同风格的方法,这些方法正常运行。有关我在哪里出错的建议吗?感谢
答案 0 :(得分:3)
我认为问题在于年度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'))"
答案 1 :(得分:2)
看起来您正在使用格式化的撇号。
to_char(sysdate,’YYYY’
尝试将其更改为
to_char(sysdate,'YYYY'