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]
相关推荐
laimaxgg12 分钟前
Linux关于华为云开放端口号后连接失败问题解决
linux·运维·服务器·网络·tcp/ip·华为云
浪小满14 分钟前
linux下使用脚本实现对进程的内存占用自动化监测
linux·运维·自动化·内存占用情况监测
东软吴彦祖28 分钟前
包安装利用 LNMP 实现 phpMyAdmin 的负载均衡并利用Redis实现会话保持nginx
linux·redis·mysql·nginx·缓存·负载均衡
艾杰Hydra1 小时前
LInux配置PXE 服务器
linux·运维·服务器
慵懒的猫mi1 小时前
deepin分享-Linux & Windows 双系统时间不一致解决方案
linux·运维·windows·mysql·deepin
阿无@_@1 小时前
2、ceph的安装——方式二ceph-deploy
linux·ceph·centos
PyAIGCMaster2 小时前
ollama部署及实践记录,虚拟环境,pycharm等
linux·ide·pycharm
ouliten2 小时前
最新版pycharm如何配置conda环境
linux·pycharm·conda
张飞光2 小时前
MongoDB 创建数据库
数据库·mongodb·oracle
AGI学习社3 小时前
2024中国排名前十AI大模型进展、应用案例与发展趋势
linux·服务器·人工智能·华为·llama