假设A表有两列,其中Ent_Date字段是Date型。
那如果取出Ent_Date是两个月前的数据呢?假如现在是07年1月19日,我要取出的数据是Ent_Date从06年11月1日至06年11月30日之间的数据,如何写这个Select语句?另:Oracle是不是不支持 month()函数?

解决方案 »

  1.   

    select * from your_table
    where ent_date>... and ent_date<....
      

  2.   

    要取出的数据是Ent_Date从06年11月1日至06年11月30日之间的数据select * from tablename where to_char(ent_date,'yyyymmdd')>=20061101 and to_char(ent_date,'yyyymmdd')<=20061130;
      

  3.   

    不是呀
     我的意思是“假设现在是07年1月”但是程序运行的时间不知道现在是几点啊。
    当然可以在程序的时候取得时间,然后打造打造sql语句的时间直接把年月放进去,但是我想是sql语句里面就可以直接用Ent_Date与sysdate作比较呀。
      

  4.   

    哦 我已经知道了。用where to_char(ent_date,'yyyymm')=to_char(add_months(sysdate,-2),'yyyymm')不过还是谢谢大家