DateTime time=Convert.ToDateTime(DateTime.Now.ToShortDateString());
DateTime begin=time.AddDays(-1);
DateTime end=time.AddDays(2);
string str="select * from view_kb_hz where Begin_time1>='"+begin+"' and end_time1<='"+end+"'"; 在oracle中Begin_time1,end_time1是时间格式date。此查询语句出错。ORA-01861: 文字与格式字符串不匹配。select * from view_kb_hz where begin_time1>'2004-7-8'
                                           *
ERROR 位于第 1 行:
ORA-01861: 文字与格式字符串不匹配如果把Begin_time1,end_time1定义为字符串型,虽然查询不出错,但结果不参那样就会出现。2004-7-7>2004-10-7的情况,

解决方案 »

  1.   

    select *
    from table_anme
    where operate_date >=to_date(:date1,'dd-mm-yyyy') and operate_date <=to_date(:date2,'dd-mm-yyyy')
      

  2.   

    用字符串吧,严格使用yyyy-MM-dd格式,这样可以省很多麻烦,或者试试这样写
    select * from view_kb_hz where begin_time1>to_date('2004-7-8','yyyy-mm-dd')
      

  3.   

    string str="select * from view_kb_hz where Begin_time1>=to_date('"+begin.ToShortDateString()+"','yyyy-mm-dd') and end_time1<=to_date('"+end.ToShortDateString()+"','yyyy-mm-dd')";
      

  4.   

    select * from view_kb_hz where 1=1 and Begin_time1>=to_date('2004-11-7 0:00:00','yyyy-mm-dd hh24:mi:ss') and end_time1<=to_date('2004-11-10 0:00:00','yyyy-mm-dd hh24:mi:ss')
    以上语句在执行时提示OCI-22053: 溢出错误