select * from TAB_测试 where 派件时间 BETWEEN '2011-02-01 22:03:40' and '2011-12-02 22:03:40'--字段不要加引号,加了引号数据库认为他是字符串!

解决方案 »

  1.   

    to_date('2011-02-01 22:03:40','yyyy-mm-dd hh24:mi:ss')
      

  2.   


    不加引号就是提示“-2147217913:ORA-01861: 文字与格式字符串不匹配”
      

  3.   

    select * from TAB_测试 where 派件时间 BETWEEN to_date('2011-02-01 22:03:40','yyyy-mm-dd hh24:mi:ss') and to_date('2011-12-02 22:03:40','yyyy-mm-dd hh24:mi:ss')
      

  4.   

    select * from TAB_测试 where to_char(派件时间,'yyyy-MM-dd hh24:mi:ss') between '2011-02-01 22:03:40'and '2011-12-02 22:03:40' ;
      

  5.   

    1、 派件时间是字段名吗,那你为什么要加上 引号??
    2、派件时间是Date类型的字段吗,那就要写成
     select *
      from TAB_测试
     where 派件时间 BETWEEN to_date('2011-02-01 22:03:40', 'yyyy-mm-dd hh24:mi:ss') and
           to_date('2011-12-02 22:03:40', 'yyyy-mm-dd hh24:mi:ss')
      

  6.   

    假定你的“派件时间”字段为Date类型,请参考下面的代码:select * from TAB_测试 where 派件时间 BETWEEN 
    to_date('2011-02-01 22:03:40', 'YYYY-MM-DD HH24:MI:SS' 
    and to_date('2011-12-02 22:03:40', 'YYYY-MM-DD HH24:MI:SS');
      

  7.   


    select * from TAB_测试 where 派件时间 BETWEEN 
    to_date('2011-02-01 22:03:40', 'YYYY-MM-DD HH24:MI:SS' 
    and to_date('2011-12-02 22:03:40', 'YYYY-MM-DD HH24:MI:SS');
      

  8.   

    ORA-01861: 文字与格式字符串不匹配,是你的派件时间和'2011-12-02 22:03:40'类型不一致,像楼上那样把时间to_char或者把'2011-12-02 22:03:40'to_date
      

  9.   

    你的派件时间肯定是date类型的,你原来的句子是用‘派件时间’这个字符串和那两个时间字符串进行匹配,当然没有结果了。
    to_char(派件时间,'yyyy-MM-dd hh24:mi:ss')