PL/SQL里跑
SELECT * from s_job WHERE to_date( to_char( CreateDate,'yyyy-MM-dd'),'yyyy-MM-dd') between add_months(to_date('2009-12-27','yyyy-MM-dd') , -1) and to_date('2009-12-27','yyyy-MM-dd')
没问题
但程序里
SELECT * from s_job WHERE to_date( to_char( CreateDate,'yyyy-MM-dd'),'yyyy-MM-dd') between add_months(to_date(:CREATEDATE,'yyyy-MM-dd') , -1) and to_date(:CREATEDATE,'yyyy-MM-dd')
参数为'2009-12-27',怎么就出现
“错误描述: ORA-01861: literal does not match format string”
这样的错误啊
CREATEDATE和CreateDate分别是什么数据类型?这两个必须是'yyyy-MM-dd'位数相关的,另外CREATEDATE前面怎么还有冒号?没这么用过。
兩個參數呢
public DataTable getTopCoAllJobs(string coid, string p_strDate)
{
string strSQL = "SELECT * from s_job WHERE to_date( to_char( CreateDate,'yyyy-MM-dd'),'yyyy-MM-dd') between add_months(to_date(:CREATEDATE,'yyyy-MM-dd') , -1) and to_date(:CREATEDATE,'yyyy-MM-dd') ";
OracleParameter[] objParameter = new OracleParameter[2];
objParameter[0] = new OracleParameter(":CREATEDATE", System.Data.OracleClient.OracleType.DateTime, 8);
objParameter[0].Value = p_strDate;
objParameter[1] = new OracleParameter(":CREATEDATE", System.Data.OracleClient.OracleType.DateTime, 8);
objParameter[1].Value = p_strDate;
return ORLHelper.ExecuteReadTable(strSQL, objParameter);
}