.NET Oracle.ManagedDataAccess.Client日期转换无效

eanckbw9  于 2023-11-17  发布在  Oracle
关注(0)|答案(1)|浏览(137)

我正在将一些旧的VBScript转换为.NET控制台应用程序。此SQL在VBScript中以及Oracle SQL Developer中运行良好,甚至在使用ODBC的MS Access中也是如此。但是当调试我的控制台应用程序时,目标是.NET Framework 4.7并使用Oracle.ManagedDataAccess NuGet包版本21.12.0,我得到一个异常“Specified cast is not valid.".我已经把问题缩小到一个日期问题.在我的SELECT中,我从CURRENT_DATE中减去一个日期来计算记录的年龄. CURRENT_DATE - PROGRAM_CHANGE_LOG.MODIFY_DATE_TIME AS days. CURRENT_DATE是一个内置的-在Oracle函数中,我已经验证了MODIFY_DATE_TIME是Oracle数据类型DATE。
我对Oracle和ManagedDataAccess客户端相当陌生,不确定如何处理这个问题,因为我在其他任何地方都尝试过。

Dim dataTable As New DataTable
       
            Using oracleConnection As New OracleConnection(ProdConnectionString)
                Dim oracleCommand As OracleCommand = oracleConnection.CreateCommand()
                oracleCommand.CommandText = "SELECT DISTINCT
                                                CURRENT_DATE - PROGRAM_CHANGE_LOG.MODIFY_DATE_TIME AS days,
                                                PROGRAM_CHANGE_LOG.SEQUENCE_NBR,
                                                PROGRAM_CHANGE_LOG.FORM_NAME,
                                                FUNCTION.DESCRIPTION,
                                                USER_LIST.LAST_NAME,
                                                USER_LIST.FIRST_NAME,
                                                USER_LIST.USERID,
                                                PROGRAM_CHANGE_LOG.INITIATED_BY,
                                                PROGRAM_CHANGE_PROJECT.DESCRIPTION Project,
                                                cnt.C - 1 AS C,
                                                PROGRAM_CHANGE_LOG.STATUS
                                            FROM
                                                 ((((PROGRAM_CHANGE_LOG 
                                            LEFT JOIN 
                                                PROGRAM_CHANGE_PROJECT ON PROGRAM_CHANGE_LOG.PROJECT_CD = PROGRAM_CHANGE_PROJECT.PROJECT_CD) 
                                            LEFT JOIN 
                                                FUNCTION ON PROGRAM_CHANGE_LOG.FORM_NAME = FUNCTION.FUNCTION_NAME) 
                                            INNER JOIN 
                                                USER_LIST ON PROGRAM_CHANGE_LOG.REQUEST_BY = USER_LIST.USERID)
                                            INNER JOIN 
                                                (SELECT Count(PROGRAM_CHANGE_LOG.SEQUENCE_NBR) C, 
                                                    PROGRAM_CHANGE_LOG.FORM_NAME
                                                FROM 
                                                    PROGRAM_CHANGE_LOG 
                                                WHERE 
                                                    PROGRAM_CHANGE_LOG.STATUS IN ('OPEN','TEST','QUES') 
                                                GROUP BY 
                                                    PROGRAM_CHANGE_LOG.FORM_NAME) cnt ON PROGRAM_CHANGE_LOG.FORM_NAME = cnt.FORM_NAME) 
                                            INNER JOIN 
                                                PROGRAM_CHANGE_NOTES ON PROGRAM_CHANGE_LOG.SEQUENCE_NBR = PROGRAM_CHANGE_NOTES.SEQUENCE_NBR
                                            GROUP BY 
                                                current_date-PROGRAM_CHANGE_LOG.MODIFY_DATE_TIME, 
                                                PROGRAM_CHANGE_LOG.SEQUENCE_NBR, 
                                                PROGRAM_CHANGE_LOG.FORM_NAME, 
                                                FUNCTION.DESCRIPTION, 
                                                USER_LIST.LAST_NAME, 
                                                USER_LIST.FIRST_NAME, 
                                                PROGRAM_CHANGE_LOG.INITIATED_BY, 
                                                PROGRAM_CHANGE_PROJECT.DESCRIPTION, 
                                                cnt.C, 
                                                PROGRAM_CHANGE_LOG.STATUS, 
                                                USER_LIST.USERID
                                            HAVING 
                                                PROGRAM_CHANGE_LOG.STATUS IN ('TEST', 'QUES') 
                                            ORDER BY 
                                                days DESC"
        
                oracleCommand.CommandType = CommandType.Text

                 Try
                    oracleConnection.Open()
                    Dim oracleDataAdapter As New OracleDataAdapter(oracleCommand)
                    oracleDataAdapter.Fill(dataTable)
                    oracleConnection.Close()
                Catch ex As Exception
                    'WriteLog(ex)
                End Try

            End Using

            Return dataTable

    End Function```

字符串

qmb5sa22

qmb5sa221#

找到一个变通办法
错误来自Oracle.ManagedDataAccess NuGet包。堆栈跟踪中的“GetDeclare”提示我...


的数据
查询在OracleSQLDeveloper中返回小数。



因此,我在.NET应用程序的查询中添加了一个ROUND函数,它现在返回一个DataTable,而不会引发异常。ROUND(CURRENT_DATE - PROGRAM_CHANGE_LOG.MODIFY_DATE_TIME) AS days,



感谢您的评论。再次新的Oracle,这不是我的查询,它已经在VBScript中使用多年。

相关问题