日期:2014-05-20  浏览次数:20695 次

求教个问题,谢谢大家帮忙
我从页面传来了个String类型的参数(buytime),buytime的格式为YYYY-MM,
ORACLE的buytime则是Date类型的,我想通过传过来的值,查询出YYYY-MM这月的所有数据。
开始的时候我想用
  String year =buytime.substring(0,4);
String month=buytime.substring(5, 7);
System.out.println(year+"-"+month);
String before = year+"-"+month+"-"+day;
  SimpleDateFormat f = new SimpleDateFormat("YYYY-MM-DD");
Date d =new Date();
try {  
d = f.parse(before);
  }
catch (ParseException e)
{
e.printStackTrace();
}
但是发现,查的时候要小于下月的1号(如2011-04-01 00:00:00>buytime and buytime<2011-05-01 00:00:00),结果这样实施不了.后来用Calendar c = Calendar.getInstance();但还是出问题,菜鸟学艺不精,求指点下

------解决方案--------------------
最简单的办法:
SQL code

select * from table where to_char(column,'yyyy-mm') = buytime;