VB.net 函数给出 ORA-00911 无效字符错误

发布于 2024-12-04 07:01:39 字数 1259 浏览 0 评论 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 无效字符错误。我还有其他相同风格的方法,并且这些方法运行正常。请问我哪里出错了有什么建议吗?谢谢

 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅笑轻吟梦一曲 2024-12-11 07:01:39

我认为问题在于该年份的 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'))"

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:

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

with

command.CommandText = "select VAL1, VAL2, Year from local.proc where id = :idnumber and Year = to_number(to_char(sysdate,'YYYY'))"
孤城病女 2024-12-11 07:01:39

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

to_char(sysdate,’YYYY’

尝试将其更改为

to_char(sysdate,'YYYY'

It looks like you are using formatted apostrophes.

to_char(sysdate,’YYYY’

try change it to

to_char(sysdate,'YYYY'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文