㈠ oracle计算N个工作日后的日期,过滤法
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Vector;
class MyCalander
{
private int year, month, day;
private Date startDay;
private Vector<Date> holidays;
public MyCalander()
{
startDay = new Date();
holidays = new Vector<Date>();
}
public void SetStartDay(String str)
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
try {
startDay = sdf.parse(str);
} catch (ParseException e) {
e.printStackTrace();
}
}
public void SetHoliday(String str)
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
Date hd = new Date();
try {
hd = sdf.parse(str);
holidays.add(hd);
} catch (ParseException e) {
e.printStackTrace();
}
}
public void GetWorkDay(int n)
{
Calendar calendar = Calendar.getInstance();
Date cursorDay = startDay;
for(int i = 0; i < n; i++)
{
calendar.setTime(cursorDay);
do{
calendar.add(Calendar.DATE, 1);
cursorDay = calendar.getTime();
}while(calendar.get(Calendar.DAY_OF_WEEK) == 1 ||
calendar.get(Calendar.DAY_OF_WEEK) == 7 ||
holidays.contains(calendar.getTime()));
}
System.out.println("The day is :" + cursorDay);
}
}
public class test
{
public static void main(String [] args)
{
MyCalander myCalander = new MyCalander();
myCalander.SetStartDay("2013/2/25");
myCalander.SetHoliday("2013/3/11");
myCalander.SetHoliday("2013/3/8");
/************************************************
* connect database and set holidays here.
* for(...)
* myCalander.SetHoliday("yyyy/mm/dd");
***********************************************/
myCalander.GetWorkDay(10);
}
执行结果:
C:\>java test
The day is :Wed Mar 13 00:00:00 JST 2013
㈡ Oracle Sql 查询按时分过滤时间区段
SQL>CREATETABLET(KSSJDATE,JSSJDATE);
表已创建。
SQL>INSERTINTOTVALUES(to_date('09:30','HH24:MI'),to_date('11:30','HH24:MI'));
已创建1行。
SQL>COMMIT;
提交完成。
SQL>SELECTTO_CHAR(KSSJ+((ROWNUM-1)/48),'HH24:MI')KSSJ,TO_CHAR(KSSJ+(ROWNUM/48),'HH24:MI')JSSJ
2FROMTCONNECTBYROWNUM<=4;
KSSJJSSJ
----------
09:3010:00
10:0010:30
10:3011:00
11:0011:30
是你说的意思不?
㈢ 要求:oracle数据库,按照时间间隔2分钟查询数据,结果如第一行数据是13:55的数据,第二条就是13:57的
如果是每隔2分钟做一次查询就用job 调用,如果是按照2分钟来分开数据,就写存储过程,这个和按照天来分割数据是一样的,只是时间上改改而已啊