关于时间比较,ORA-01861: literal does not match format string

来源:互联网 发布:淘宝卖的印度威格拉 编辑:程序博客网 时间:2024/05/01 00:25

 项目中数据库的数据是date类型, 页面获取的的是String ,涉及到去数据查询,直接将获取的字符串去比较会报出ORA-01861: literal does not match format string

解决办法:

  

1). ORA-01861: 文字与格式字符串不匹配

2). 必须指定日期格式
    to_date('2010-05-11 14:20:24' , 'yyyy-mm-dd hh24:mi:ss')

3). 比较时间也可以将数据的时间字段to_char('时间','yyyy-mm-dd hh24:mi:ss').变成字符串,再去按字符串比较.
    当然你的字符串'2010-5-1'也要to_char(to_date('2010-5-1','yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss').


  

0 0