一张表里面有个字段 A 是date类型存放的是日期和时分秒怎么查询日期在2012年2月1日的记录呢?select * from table where A='2012-02-01'吗显然不对 该怎么写呢 谢谢

解决方案 »

  1.   

    不对,需要使用to_data()函数进行转换
      

  2.   

    select * from table where to_date(A)='2012-02-01'这么写?
      

  3.   

    select * from table where to_char(A,'YYYY-MM-DD')='2012-02-01'
      

  4.   

    select * from table where a=to_date('2012-02-01','yyyy-mm-dd')
      

  5.   


    这个是有点问题的,A字段一般不会是2012-02-01,一般默认会精确到秒...
    所以一般时间查询的时候,使用将时间转化为字符串比较,同三楼:select * from table where to_char(a,'yyyymmdd') = '20120201';
      

  6.   


    select * from tb1 where to_char(A,'yyyy-mm-dd')='2012-02-01'
      

  7.   


    select * from table where A=To_Date('2012-02-01','YYYY-MM-DD');
      

  8.   

    SELECT * FROM TABLE WHERE A LIKE DATE '2012-02-01';
      

  9.   

    select * from table where to_char(A,'YYYY-MM-DD')='2012-02-01'
      

  10.   

    http://www.cnblogs.com/chuncn/archive/2009/04/29/1381282.html
    把日期函数都熟悉一下 建议
      

  11.   

    where A between to_date('03-FEB-12 00:00:00','DD-MON-YY HH24:MI:SS') and to_date('03-FEB-12 23:59:59','DD-MON-YY HH24:MI:SS');