select autoid from order_t where acceptdate=to_date('2010-01-01', 'yyyy-MM-dd')
数据库里明明有满足条件的记录可是却出不来.为什么
select autoid from order_t where acceptdate>=to_date('2010-01-01', 'yyyy-MM-dd') and acceptdate<=to_date('2010-01-01','yyyy-MM-dd')
上面的两个都不行..
高手指教

解决方案 »

  1.   

     把数据拿出来,
    按你的SQL,应该是没有符合条件的数据
      

  2.   


    你数据库中acceptdate字段存放的日期格式是什么样的? 是不是yyyy-MM-dd? 那么就查不出
    你试试这样有数据没的呢?select autoid from order_t where To_Char(acceptdate,'yyyy-MM-dd')='2010-01-01';
      

  3.   

    select autoid from order_t where to_char(acceptdate, 'yyyy-MM-dd') = '2010-01-01'
    用这句试试
    或者
    select autoid from order_t where acceptdate between to_date('2010-01-01', 'yyyy-MM-dd') and to_date('2010-01-02','yyyy-MM-dd')
      

  4.   

    怎么查询得出来,你的accptdate肯定有时分秒啊。。把你的acceptdate这个字段trunc下就可以了。。select autoid from order_t where trunc(acceptdate)=to_date('2010-01-01', 'yyyy-MM-dd')
      

  5.   

    你数据库里存的时间是不是精确到时分秒了?
    2010-01-01 12:12:12 和2010-01-01是不等的To_Char(acceptdate,'yyyy-MM-dd')='2010-01-01';
      

  6.   

    select autoid from order_t where trunc(acceptdate)=to_date('2010-01-01', 'yyyy-MM-dd')
      

  7.   


    scott@ORCL> insert into emp 
      2  (empno,ename,hiredate) values(8888,'john',to_date('1981-02-20 10:25:32',
      3  'yyyy-mm-dd hh24:mi:ss'));1 row created.scott@ORCL> select * from emp where to_char(hiredate,'yyyy-mm-dd')='1981-02-20'
      2  ;     EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
    ---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
          8888 john                            1981-02-20 10:25:32
          7499 ALLEN      SALESMAN        7698 1981-02-20 00:00:00       1500        300         30scott@ORCL> select * from emp
      2  where to_char(hiredate,'yyyy-mm-dd')>='1981-02-19'  
      3  and to_char(hiredate,'yyyy-mm-dd')<'1981-02-21';     EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
    ---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
          8888 john                            1981-02-20 10:25:32
          7499 ALLEN      SALESMAN        7698 1981-02-20 00:00:00       1500        300         30
      

  8.   

    to_date() 报错,to_char() 可查询结果,这是什么?请高人指点