`

Oracle——按时间段查询

    博客分类:
  • SQL
 
阅读更多

按照多个时间段查询:包括秒

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[i];
			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[i];
			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();
	}
 

 

分享到:
评论

相关推荐

    Oracle数据库——数据库安全性管理.pdf

    (2)Oracle可以在两个层次上限制⽤户对系统资源的使⽤: 会话级:若在⼀个会话时间段内超过了资源限制参数的最⼤值,Oracle将停⽌当前的操作,回退未提交的事务,并断开连接。 调⽤级:若在调⽤级上,⼀条sql语句...

    ORACLE EBS R12弹性域笔记整理——说明性弹性域v1.0

    前段时间整理一下说明性弹性域的学习资料,分享给大家。

    Oracle SQL高级编程(资深Oracle专家力作,OakTable团队推荐)--随书源代码

    他认为对于SQL的学习是永无止境的,相信每一个查询Oracle数据库的人都需要精通SQL语言,才能写出高效的查询。他参与本书的编写就是为了帮助别人实现这一目标。 目录 封面 -11 封底 -10 扉页 -9 版权 -8 版权声明 -7...

    Oracle Database 11g初学者指南--详细书签版

     ·核心概念——oracle database 11g主题呈现在按逻辑组织的章节中  ·主要内容——每章要介绍的具体内容列表  ·实践练习——演示如何应用在每章学到的关键技术  ·学习效果测试——对学习效果的快速自我评估 ...

    Oracle.ManagedDataAccess.7z

    “ODP.NET Managed”发布已经有一段时间了,近期正好有一个新项目,想尝试用一下,参考园子里的文章:《.NET Oracle Developer的福音——ODP.NET Managed正式推出》 到Oracle官网 下载 ODP.NET_Managed121010.zip ...

    oracle学习文档 笔记 全面 深刻 详细 通俗易懂 doc word格式 清晰 连接字符串

    简单来说是本身可视为电子化的文件柜——存储电子文件的处所,用户可以对文件中的数据运行新增、截取、更新、删除等操作。 常见的数据模型 1. 层次结构模型: 层次结构模型实质上是一种有根结点的定向有序树,IMS...

    oracle数据库11G初学者指南.Oracle.Database.11g,.A.Beginner's.Guide

    核心概念——Oracle Database 11g主题呈现在按逻辑组织的章节中 主要内容——每章要介绍的具体内容列表 实践练习——演示如何应用在每章学到的关键技术 学习效果测试——对学习效果的快速自我评估 注意——与所介绍...

    数据库课程设计——图书管理系统.doc

    目前,绝大多数流 行的关系型数据库管理系统,如Oracle, Sybase, Microsoft SQL Server, Access等都采用了SQL语言标准. SQL语言有以下几个优点: 1. 非过程化语言 SQL是一个非过程化的语言,因为它一次处理一个记录,...

    oracle数据库笔记

    补充资料——oracle安装时出现的问题 12 第二讲 Oacle数据库体系结构 14 一. 物理存储结构——(数据库载体) 14 1.数据文件(.DBF) 14 2.日志文件 (.Log) 14 1) 日志文件 15 2) 数据库工作模式 15 3.控制文件...

    Oracle 10g 开发与管理

    补充资料——oracle安装时出现的问题 12 第二讲 Oacle数据库体系结构 14 一. 物理存储结构——(数据库载体) 14 1.数据文件(.DBF) 14 2.日志文件 (.Log) 14 1) 日志文件 15 2) 数据库工作模式 15 3.控制文件...

    O r a c l e与X M L

    在此期间,他们在对Oracle的工作投入大量时间的同时尽可能保持着本书的进度,经历了一段真正的紧张生活。真的,任何一位作者,他们的家庭,以及Oracle出版社的编辑们,都不会忘记这段经历的。XML万岁!注意 本书的一...

    PHP开发实战1200例(第1卷).(清华出版.潘凯华.刘中华).part1

    实例120 计算查询操作的执行时间 151 实例121 查询关键字描红 152 实例122 判断上传文件的类型 153 实例123 判断邮政编码格式是否正确 154 2.10 数组 154 实例124 创建并输出数组 155 实例125 统计数组元素个数 156 ...

    PHP开发实战1200例(第1卷).(清华出版.潘凯华.刘中华).part2

    实例120 计算查询操作的执行时间 151 实例121 查询关键字描红 152 实例122 判断上传文件的类型 153 实例123 判断邮政编码格式是否正确 154 2.10 数组 154 实例124 创建并输出数组 155 实例125 统计数组元素个数 156 ...

    PLSQLDeveloper下载

    SQL 窗口——该窗口允许您输入任何SQL语句,并以栅格形式对结果进行观察和编辑,支持按范例查询模式,以便在某个结果集合中查找特定记录。另外,还含有历史缓存,您可以轻松调用先前执行过的SQL语句。该SQL编辑器...

    php程序设计课程大作业——基于PHP、MySQL的web端借还书系统.zip

    PHP内置丰富的数据类型(如整型、浮点型、字符串、数组、对象等),并提供了大量的预定义函数,涵盖了字符串操作、数学运算、文件系统处理、日期时间处理、数据库连接等常见功能,极大提高了开发效率。 在Web开发中...

    LECCO SQL Expert (智能自动SQL优化)

    目前在商用数据库领域LECCO TechnologyLimited(灵高公司)拥有该技术并提供使用该技术的自动优化产品——LECCO SQL Expert,其支持Oracle、Sybase、MS SQLServer和IBMDB2数据库平台。该产品针对数据库应用的开发和...

    php网络开发完全手册

    13.3.2 ORACLE 207 13.3.3 SYBASE 207 13.3.4 DB2 207 13.3.5 SQL Server 207 13.4 SQL语言简介 207 13.5 常见的数据库设计问题 208 13.6 关系型数据库的设计原则 209 13.6.1 第一范式(1NF) 209 13.6.2 第二范式...

    这可能就是银行需要的开发测试架构?

    今天在TWT社区看到一个问题,在这里分享一下 ...(1)数据库数据大后,expdp导出的时间较长,一些OLAP数据库已经无法在非业务时间段完成备份。 (2)导出时对生产IO影响较大,会影响夜间一些批处理工作的。

Global site tag (gtag.js) - Google Analytics