前提条件:作为条件的date字段存在oracle 表里类型为Date,现需把该字段作为其它表查询条件入参。
-- create_time 为Date类型 last_time 为Date类型
select * from test_temp where create_time > last_time; -- 抛异常
select * from test_temp where create_time > to_date(last_time,'yyyy-mm-dd hh24:mi:ss'); -- 抛异常日期后有个.0 例:2022-09-15 19:30:20.0
select * from test_temp where create_time > to_char(last_time,'yyyy-mm-dd hh24:mi:ss');-- 抛异常Date直传日期中间带空格例:2022 - 09 - 15 19 : 30 : 20
-- 先在service层把 last_time用SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); String lastTime = ft.format(last_time); 使用作为入参传给SQL,该SQL正常执行
select * from test_temp where create_time > to_char(lastTime ,'yyyy-mm-dd hh24:mi:ss');