㈠ 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分鍾來分開數據,就寫存儲過程,這個和按照天來分割數據是一樣的,只是時間上改改而已啊