ORA-00932:不一致的数据类型:预期NUMBER得到DATE

时间:2016-07-20 13:38:58

标签: oracle c#-4.0 oracle11g

我不知道为什么我会得到这个例外。参数顺序相同。数据类型没问题。我也试过这个:TO_DATE(:UPDATE_DATE,' MM / DD / YYYY HH24:MI:SS')没有任何改变。我的insert命令与date字段成功运行此更新命令中的问题是什么?当我删除日期字段时,我能够成功更新,因此我确信UPDATE_DATE列存在问题。有什么建议?

var commandTxt = @"UPDATE CFG_PERMISSION 
                                SET CATEGORY= :CATEGORY,                                    
                                    TYPE_CODE = :TYPE_CODE, 
                                    LOCATION_ID = :LOCATION_ID, 
                                    OBJECT_ID = :OBJECT_ID, 
                                    NAME = :NAME, 
                                    DESCRIPTION = :DESCRIPTION,  
                                    UPDATE_DATE = :UPDATE_DATE,     
                                    UPDATED_BY = :UPDATED_BY                                        
                                WHERE ID = :SCOPE_ID";


            OracleParameter[] parameters = new OracleParameter[] {
                new OracleParameter(":SCOPE_ID", OracleDbType.Long,10, cfgRoleScope.ID, ParameterDirection.Input),
                new OracleParameter(":CATEGORY",OracleDbType.Varchar2,30, cfgRoleScope.CATEGORY, ParameterDirection.Input),
                new OracleParameter(":TYPE_CODE", OracleDbType.Varchar2,30, cfgRoleScope.TYPE_CODE,ParameterDirection.Input),
                new OracleParameter(":LOCATION_ID",OracleDbType.Long,10, DBNull.Value, ParameterDirection.Input),
                new OracleParameter(":OBJECT_ID", OracleDbType.Long,10, DBNull.Value, ParameterDirection.Input),
                new OracleParameter(":NAME", OracleDbType.Varchar2,50, cfgRoleScope.NAME,ParameterDirection.Input),
                new OracleParameter(":DESCRIPTION", OracleDbType.Varchar2,50, cfgRoleScope.DESCRIPTION,ParameterDirection.Input),
                new OracleParameter(":UPDATE_DATE",OracleDbType.Date,DateTime.Now,ParameterDirection.Input),
                new OracleParameter(":UPDATED_BY",OracleDbType.Long,6,cfgRoleScope.UPDATED_BY, ParameterDirection.Input),                    

            };

            if (cfgRoleScope.OBJECT_ID > 0)
                parameters[4].Value = cfgRoleScope.OBJECT_ID;

            if (cfgRoleScope.LOCATION != null)
                parameters[3].Value = cfgRoleScope.LOCATION.ID;

            var command = db.CreateCommand();
            command.Parameters.AddRange(parameters.ToArray());
            command.CommandText = commandTxt;
            command.ExecuteNonQuery();

1 个答案:

答案 0 :(得分:0)

将scope_id参数添加到最后解决了我的问题。最终参数应该是这样的。

OracleParameter[] parameters = new OracleParameter[] {                    
                new OracleParameter(":CATEGORY",OracleDbType.Varchar2,30, cfgRoleScope.CATEGORY, ParameterDirection.Input),
                new OracleParameter(":TYPE_CODE", OracleDbType.Varchar2,30, cfgRoleScope.TYPE_CODE,ParameterDirection.Input),
                new OracleParameter(":LOCATION_ID",OracleDbType.Long,10, DBNull.Value, ParameterDirection.Input),
                new OracleParameter(":OBJECT_ID", OracleDbType.Long,10, DBNull.Value, ParameterDirection.Input),
                new OracleParameter(":NAME", OracleDbType.Varchar2,50, cfgRoleScope.NAME,ParameterDirection.Input),
                new OracleParameter(":DESCRIPTION", OracleDbType.Varchar2,50, cfgRoleScope.DESCRIPTION,ParameterDirection.Input),
                new OracleParameter(":UPDATE_DATE",OracleDbType.Date,cfgRoleScope.UPDATE_DATE,ParameterDirection.Input),
                new OracleParameter(":UPDATED_BY",OracleDbType.Long,6,cfgRoleScope.UPDATED_BY, ParameterDirection.Input),                    
                new OracleParameter(":SCOPE_ID", OracleDbType.Long,10, cfgRoleScope.ID, ParameterDirection.Input),

            };