select *
      from b
      where
      to_char(savetime,'yyyy-mm-dd hh24:mi')>to_char(sysdate,'yyyy-mm-dd hh24:mi')-30
请问,我用这语句查询当前时间前半小时的记录,为什么总是报'无效数字'错误,要怎样写才正确?

解决方案 »

  1.   

    to_char()是转化成字符型的,怎么能与数字30相减,用to_number()
      

  2.   

    to_char(sysdate,'yyyy-mm-dd hh24:mi')-30 转成字符了,还去减30,应该是
    to_char(sysdate-30,'yyyy-mm-dd hh24:mi')吧
      

  3.   


    在oracle中,时间类型的值直接相减就可以了,得到的是天数,你可以这样写select * 
          from b 
          where 
          round(sysdate-savetime)>30;--使用四舍五入函数将小数转化成整数
      

  4.   


    select  sysdate,sysdate-1/(24*60)*30 from dual;
      

  5.   


    select * 
          from b 
          where 
            round((sysdate-savetime)*24*60) <= 30;
      

  6.   

    用这个吧select *
          from b
          where
          to_date(savetime,'yyyy-mm-dd hh24miss')> (sysdate - TO_DSINTERVAL('0 00:30:00.00'))