VB.net 函数给出 ORA-00911 无效字符错误
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 无效字符错误。我还有其他相同风格的方法,并且这些方法运行正常。请问我哪里出错了有什么建议吗?谢谢
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
This function is giving an ORA-00911 invalid character error. I have other methods of the same style and these are functioning correctly. Any advise on where I am going wrong here please? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为问题在于该年份的 SQL 语句中的引号错误,即:
'YYYY'
将其更改为
'YYYY'
将行:替换
为
I think the issue is with the wrong quotes in the SQL statement for the year i.e. :
’YYYY’
Change it to
'YYYY'
Replace the line:
with
您似乎正在使用格式化的撇号。
尝试将其更改为
It looks like you are using formatted apostrophes.
try change it to