簡體   English   中英

VB.net函數給出ORA-00911無效字符錯誤

[英]VB.net function giving ORA-00911 invalid character error

 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無效字符錯誤。 我有其他相同風格的方法,這些方法運行正常。 有什么建議我要去哪里錯嗎? 謝謝

我認為問題在於該年份的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'))"

看來您正在使用格式化的撇號。

to_char(sysdate,’YYYY’

嘗試將其更改為

to_char(sysdate,'YYYY'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM