ORM Bee,如何使用Oracle的TO_DATE函数?

ORM Bee,如何使用Oracle的TO_DATE函数?

在Bee V2.4.0,可以这样使用:

java 复制代码
        LocaldatetimeTable selectBean=new LocaldatetimeTable();
        Condition condition=BF.getCondition();
        condition.op("localdatetime", Op.ge, new TO_DATE("2024-07-08", "YYYY-MM-DD"));
        
        List<LocaldatetimeTable> list=suidRich.select(selectBean,condition);
        Printer.printList(list);

日志:

sql 复制代码
[INFO] [Bee] -------- Bee    2.4.0 -------- 
[INFO] [Bee] -------- Honey  2.4.0 -------- 
[INFO] [Bee] -------- BeeExt 2.4.0 -------- 
[DEBUG] [Bee] ========= Bee    buildId  2.4.0.7
[DEBUG] [Bee] ========= Honey  buildId  2.4.0.7
[DEBUG] [Bee] ========= BeeExt buildId  2.4.0.7
[INFO] [Bee] ========= get the dbName via url is: Oracle
[INFO] [Bee] select SQL: select id,name,datetime,timestamp,localdatetime,ext,json from localdatetime_table where localdatetime>=TO_DATE(?, 'YYYY-MM-DD')   [values]: 2024-07-08(String)
[INFO] [Bee] select SQL:  ( ExecutableSql )
select id,name,datetime,timestamp,localdatetime,ext,json from localdatetime_table where localdatetime>=TO_DATE('2024-07-08', 'YYYY-MM-DD') ;
[DEBUG] Use OriginalConn!
[INFO] [Bee]  | <--  select rows: 2
[INFO] LocaldatetimeTable[id=12,name=null,datetime=null,timestamp=null,localdatetime=2024-07-08T23:55:35.534,ext=null,json=null]
[INFO] LocaldatetimeTable[id=13,name=null,datetime=null,timestamp=null,localdatetime=2024-07-08T23:56:01.521,ext=null,json=null]

condition.op("localdatetime", Op.ge, new TO_DATE("2024-07-08", "YYYY-MM-DD"));

对应SQL:

//where localdatetime>=TO_DATE('2024-07-08', 'YYYY-MM-DD') ;

sql 复制代码
select * from ORDERS where total between 20 and 94
与
select * from ORDERS where total>=20 and total<=94
是等价的.

以下是Java的例子.

java 复制代码
public class LocalDateTimeExam3 {

	public static void main(String[] args) throws Exception {
		LocaldatetimeTable bean = new LocaldatetimeTable();
		bean.setId(10);
//		bean.setLocaldatetime(LocalDateTime.now());
		bean.setTimestamp(new Timestamp(System.currentTimeMillis()));

		SuidRich suidRich = BF.getSuidRich();
//		int a=suidRich.insert(bean);
//		Logger.info("insert num:"+a);

		LocaldatetimeTable selectBean = new LocaldatetimeTable();
		Condition condition = BF.getCondition();
		condition.op("localdatetime", Op.ge, new TO_DATE("2024-07-08", "YYYY-MM-DD"));

		List<LocaldatetimeTable> list = suidRich.select(selectBean, condition);
		Printer.printList(list);

		String dateString = "2024-07-08T23:55:35.534";
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
		Date parsedDate = dateFormat.parse(dateString);
		Timestamp timestamp = new Timestamp(parsedDate.getTime());
//	        System.out.println("Timestamp in Java format: " + timestamp);

		condition = BF.getCondition();
		condition.op("localdatetime", Op.ge, timestamp);
		condition.op("localdatetime", Op.le, timestamp); //改为另一个timestamp的值即可
		list = suidRich.select(selectBean, condition);
		Printer.printList(list);
	}

使用到:

java 复制代码
	/**
	 * Add a expression condition.
	 * <br>This method cannot be used for SQL update set part.
	 * <br>When Op type is Op.in/Op.notIn,Object type can be List,Set,Number,Number[],String.
	 * @param field Field name
	 * @param op operator
	 * @param value Value of the field.
	 * @return Condition
	 */
	public Condition op(String field, Op op, Object value);

日志:

sql 复制代码
[INFO] [Bee] -------- Bee    2.4.0 -------- 
[INFO] [Bee] -------- Honey  2.4.0 -------- 
[INFO] [Bee] -------- BeeExt 2.4.0 -------- 
[DEBUG] [Bee] ========= Bee    buildId  2.4.0.7
[DEBUG] [Bee] ========= Honey  buildId  2.4.0.7
[DEBUG] [Bee] ========= BeeExt buildId  2.4.0.7
[INFO] [Bee] ========= get the dbName via url is: Oracle
[INFO] [Bee] select SQL: select id,name,datetime,timestamp,localdatetime,ext,json from localdatetime_table where localdatetime>=TO_DATE(?, 'YYYY-MM-DD')   [values]: 2024-07-08(String)
[INFO] [Bee] select SQL:  ( ExecutableSql )
select id,name,datetime,timestamp,localdatetime,ext,json from localdatetime_table where localdatetime>=TO_DATE('2024-07-08', 'YYYY-MM-DD') ;
[DEBUG] Use OriginalConn!
[INFO] [Bee]  | <--  select rows: 2
[INFO] LocaldatetimeTable[id=12,name=null,datetime=null,timestamp=null,localdatetime=2024-07-08T23:55:35.534,ext=null,json=null]
[INFO] LocaldatetimeTable[id=13,name=null,datetime=null,timestamp=null,localdatetime=2024-07-08T23:56:01.521,ext=null,json=null]
[INFO] [Bee] select SQL: select id,name,datetime,timestamp,localdatetime,ext,json from localdatetime_table where localdatetime>=? and localdatetime<=?   [values]: 2024-07-08 23:55:35.534(java.sql.Timestamp),2024-07-08 23:55:35.534(java.sql.Timestamp)
[INFO] [Bee] select SQL:  ( ExecutableSql )
select id,name,datetime,timestamp,localdatetime,ext,json from localdatetime_table where localdatetime>=2024-07-08 23:55:35.534 and localdatetime<=2024-07-08 23:55:35.534 ;
[INFO] [Bee]  | <--  select rows: 1
[INFO] LocaldatetimeTable[id=12,name=null,datetime=null,timestamp=null,localdatetime=2024-07-08T23:55:35.534,ext=null,json=null]
相关推荐
TeYiToKu7 分钟前
笔记整理—linux驱动开发部分(9)framebuffer驱动框架
linux·c语言·arm开发·驱动开发·笔记·嵌入式硬件·arm
dsywws10 分钟前
Linux学习笔记之时间日期和查找和解压缩指令
linux·笔记·学习
yeyuningzi18 分钟前
Debian 12环境里部署nginx步骤记录
linux·运维·服务器
BearHan21 分钟前
Sqlsugar调用Oracle的存储过程
oracle·存储过程·orm
上辈子杀猪这辈子学IT36 分钟前
【Zookeeper集群搭建】安装zookeeper、zookeeper集群配置、zookeeper启动与关闭、zookeeper的shell命令操作
linux·hadoop·zookeeper·centos·debian
superman超哥36 分钟前
04 深入 Oracle 并发世界:MVCC、锁、闩锁、事务隔离与并发性能优化的探索
数据库·oracle·性能优化·dba
minihuabei41 分钟前
linux centos 安装redis
linux·redis·centos
lldhsds2 小时前
书生大模型实战营第四期-入门岛-1. Linux前置基础
linux
wowocpp2 小时前
ubuntu 22.04 硬件配置 查看 显卡
linux·运维·ubuntu
Mephisto.java2 小时前
【大数据学习 | kafka高级部分】kafka的kraft集群
大数据·sql·oracle·kafka·json·hbase