日期:2014-05-17  浏览次数:20962 次

这个sql语句老报错,应该怎样改?
SQL code

select count(*)  from  (  
 select DNAorderno,Order_no,LTime,Settledate,Pay_fee,Commimission,Tel,order_Status,Order_Type 
 from(select b.orderno DNAorderno,a.order_no,a.add_time as LTime,b.settledate,a.pay_fee,null as Commimission,Tel,order_Status,Order_Type  from  ercp_t_order a 
 left join ercp_payresult b on a.order_no=b.reference where a.pay_id=5 and a.pay_status=1 ) 
 where ( LTime >='2012-02-19 00:00:00.000' and LTime<='2012-03-19 23:59:59.999' and   1=1   )  )  t 



LTime >='2012-02-19 00:00:00.000' and LTime<='2012-03-19 23:59:59.999' 

就是这句错啦,为什么字段类型自动变成字符串呢?
我想包一层,写个通用的语句。
谢谢。

------解决方案--------------------
错误信息是啥!
------解决方案--------------------
试一下吧


oracle普通的DATE类型不支持秒以后的格式,且一定要进行类型转换。
'2012-02-19 00:00:00.000'应改为

LTime >= to_date('2012-02-19 00:00:00','yyyy-mm-dd hh24:mi:ss')
------解决方案--------------------
数据类型不对,怎么比较。现在的人好可爱!
------解决方案--------------------
如果要使用日期型常量的话,必须按照下面的格式。

LTime >= timestamp '2012-02-19 00:00:00.000' and LTime<= timestamp '2012-03-19 23:59:59.999'
------解决方案--------------------
两边的数据类型不一样 ,3楼和5楼的都可以完成
------解决方案--------------------
SQL code

select count(*)  from  (  
   select DNAorderno,
          Order_no,
          LTime,
          Settledate,
          Pay_fee,
          Commimission,
          Tel,
          order_Status,
          Order_Type
   from(select b.orderno 
               DNAorderno,
               a.order_no,
               a.add_time as LTime,
               b.settledate,
               a.pay_fee,null as Commimission,
               Tel,order_Status,
               Order_Type  
        from  ercp_t_order a 
        left join ercp_payresult b on a.order_no=b.reference 
        where a.pay_id=5 and a.pay_status=1 
       ) test
 
   where test.LTime >=to_date('2012-02-19 00:00:00.000','你需要的日期格式') and test.LTime<=to_date('2012-03-19 23:59:59.999','你需要的日期格式') and   1=1  
)  t

------解决方案--------------------
to_timestamp('2012-02-19 00:00:00.000','yyyy-mm-dd hh24:mi:ss.ff3')