设为首页 收藏本站
查看: 650|回复: 0

[经验分享] Oracle——按时间段查询

[复制链接]

尚未签到

发表于 2016-7-19 12:59:59 | 显示全部楼层 |阅读模式
  按照多个时间段查询:包括秒
  


String sql = "from Sedimentpermit";
sql += " where Carno like '%" + carno + "%'";
sql += " and road like '%" + road + "%'";
sql += " and to_char(VALIDDATE,'yyyy-mm-dd') >= '" + validDate
+ "'";
sql += " and ((to_char(BEGINDATE1,'yyyy-mm-dd hh24:mi:ss') <= '"
+ time + "'";
sql += " and to_char(ENDDATE1,'yyyy-mm-dd hh24:mi:ss') >= '" + time
+ "') ";
sql += " or (to_char(BEGINDATE2,'yyyy-mm-dd hh24:mi:ss') <= '"
+ time + "'";
sql += " and to_char(ENDDATE2,'yyyy-mm-dd hh24:mi:ss') >= '" + time
+ "') ";
sql += " or (to_char(BEGINDATE3,'yyyy-mm-dd hh24:mi:ss') <= '"
+ time + "'";
sql += " and to_char(ENDDATE3,'yyyy-mm-dd hh24:mi:ss') >= '" + time
+ "')) ";
   
  常用的日期转换方法
  


//获得服务器时间
public static Date getServerTime(Context con) {
String seamurl = DBHelp.getConfigValue(con, ConfigKey.seamurl);
if (seamurl.equals("")) {
seamurl = StringHelp.getResSeamUrl(con);
}
seamurl += "?requestType=getTime";
String bs = "";
Date date = null;
try {
for (int i = 0; i <= 5; i++) {
bs = HttpHelp.getHttpBack(seamurl);
if (bs.contains("time")) {
date = DateHelp.stringToDate2(StringHelp.getXMLAtt(bs,
"time"));
return date;
}
// Thread.sleep(300);
}
} catch (Exception e) {
e.printStackTrace();
LogHelp.Log2SDErr(e);
bs = "<time>" + getCurrentTime() + "</time>";
}
LogHelp.LogI("服务器时间=" + bs);
if (date == null) {
bs = "<time>" + getCurrentTime() + "</time>";
date = DateHelp.stringToDate2(StringHelp.getXMLAtt(bs, "time"));
}
return date;
}
public static String convertDate(Date date, String format) {
if (date != null) {
DateFormat format1 = new SimpleDateFormat(format);
String s = format1.format(date);
return s;
}
return "";
}
public static String getCurTime() {
return convertDate(new Date(), "HH:mm");
}
public static String getCurrentTime() {
return convertDate(new Date(), "yyyy-MM-dd HH:mm:ss");
}

public static String getCurDate() {
return convertDate(new Date(), "yyyy-MM-dd");
}
public static String getCurDate(Date date) {
return convertDate(date, "yyyy-MM-dd");
}
public static String getFormateDate(int type, Date date) {
// 获取系统时间,并格式化
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int year = calendar.get(Calendar.YEAR);
int mounth = calendar.get(Calendar.MONTH) + 1;
int day = calendar.get(Calendar.DATE);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int min = calendar.get(calendar.MINUTE);
int secound = calendar.get(calendar.SECOND);
// 格式一:2011-11-1 12-12-66+mima 作为图片文件名
if (type == 1) {
String a[] = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" };
Random random = new Random();
int i = random.nextInt(10);
String extra = a;
String mima = MiMa.jiami(extra + AddZero(min) + AddZero(secound)
+ random.nextInt(10), 6);
return String.valueOf(year) + "-" + AddZero(mounth) + "-"
+ AddZero(day) + " " + AddZero(hour) + "-" + AddZero(min)
+ "-" + AddZero(secound) + " " + mima;
}
// 格式二:2011年11月1日 12时12分45秒 写在照片上
else if (type == 2) {
return String.valueOf(year) + "年" + AddZero(mounth) + "月"
+ AddZero(day) + "日  " + AddZero(hour) + "时" + AddZero(min)
+ "分" + AddZero(secound) + "秒";
}
// 格式三:2011-11-1 12-12-11 作为录音文件名
else if (type == 3) {
return String.valueOf(year) + "-" + AddZero(mounth) + "-"
+ AddZero(day) + " " + AddZero(hour) + "-" + AddZero(min)
+ "-" + AddZero(secound) + " ";
}
return null;
}
/**
* @annotation 获取指定格式的日期
*/
@SuppressWarnings("static-access")
public static String getFormateDate(int type) {
// 获取系统时间,并格式化
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
int year = calendar.get(Calendar.YEAR);
int mounth = calendar.get(Calendar.MONTH) + 1;
int day = calendar.get(Calendar.DATE);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int min = calendar.get(calendar.MINUTE);
int secound = calendar.get(calendar.SECOND);
// 格式一:2011-11-1 12-12-66+mima 作为图片文件名
if (type == 1) {
String a[] = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" };
Random random = new Random();
int i = random.nextInt(10);
String extra = a;
String mima = MiMa.jiami(extra + AddZero(min) + AddZero(secound)
+ random.nextInt(10), 6);
return String.valueOf(year) + "-" + AddZero(mounth) + "-"
+ AddZero(day) + " " + AddZero(hour) + "-" + AddZero(min)
+ "-" + AddZero(secound) + " " + mima;
}
// 格式二:2011年11月1日 12时12分45秒 写在照片上
else if (type == 2) {
return String.valueOf(year) + "年" + AddZero(mounth) + "月"
+ AddZero(day) + "日  " + AddZero(hour) + "时" + AddZero(min)
+ "分" + AddZero(secound) + "秒";
}
// 格式三:2011-11-1 12-12-11 作为录音文件名
else if (type == 3) {
return String.valueOf(year) + "-" + AddZero(mounth) + "-"
+ AddZero(day) + " " + AddZero(hour) + "-" + AddZero(min)
+ "-" + AddZero(secound) + " ";
}
return null;
}
public static String AddZero(int i) {
if (i >= 0 && i <= 9) {
return "0" + i;
}
return String.valueOf(i);
}
/**
*
* @annotation string 转 日期类型
*/
public static Date stringToDate(String string) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = null;
try {
date = sdf.parse(string);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
public static Date stringToDate2(String string) {
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = null;
try {
date = sdf.parse(string);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
/**
*
* @annotation 日期比较:都是sring型:0相等,>0大于,<0 小于
*/
public static long compareDate(String date1, String date2) {
Date beginTime = DateHelp.stringToDate(date1);
Date endTime = DateHelp.stringToDate(date2);
return beginTime.getTime() - endTime.getTime();
}
/**
*
* @annotation 日期比较:都是Date型
*/
public static long compareDate(Date date1, Date date2) {
return date1.getTime() - date2.getTime();
}

   

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-246398-1-1.html 上篇帖子: Oracle Stored Procedure Sample 下篇帖子: oracle exception when others then
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表