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]
相关推荐
watermelonoops35 分钟前
Deepin和Windows传文件(Xftp,WinSCP)
linux·ssh·deepin·winscp·xftp
疯狂飙车的蜗牛2 小时前
从零玩转CanMV-K230(4)-小核Linux驱动开发参考
linux·运维·驱动开发
远游客07134 小时前
centos stream 8下载安装遇到的坑
linux·服务器·centos
马甲是掉不了一点的<.<4 小时前
本地电脑使用命令行上传文件至远程服务器
linux·scp·cmd·远程文件上传
jingyu飞鸟4 小时前
centos-stream9系统安装docker
linux·docker·centos
超爱吃士力架4 小时前
邀请逻辑
java·linux·后端
百度智能云技术站5 小时前
广告投放系统成本降低 70%+,基于 Redis 容量型数据库 PegaDB 的方案设计和业务实践
数据库·redis·oracle
cominglately7 小时前
centos单机部署seata
linux·运维·centos
魏 无羡7 小时前
linux CentOS系统上卸载docker
linux·kubernetes·centos
CircleMouse7 小时前
Centos7, 使用yum工具,出现 Could not resolve host: mirrorlist.centos.org
linux·运维·服务器·centos