to_date和to_char的用法
to_date:将字符型转换为date型
SELECT
to_date('2011-09-20 08:30:45', 'yyyy-MM-dd hh24:mi:ss')
FROM dual;
to_char:将date转换为字符型
SELECT
to_char(SYSDATE, 'yyyy-MM-dd hh24:mi:ss')
FROM dual;
若涉及到参数比较(startTime为string类型的参数)
将数据库中的字段转换为string型与参数比较:
select * from user
where
to_char(time,'yyyy-MM-dd hh24:mi:ss') >=#{startTime,jdbcType=VARCHAR}
将参数转换为date类型与数据库中的字段比较(此种方式更为高效)
select * from user
where
time >= to_date(#{startTime,jdbcType=VARCHAR},'yyyy-MM-dd hh24:mi:ss')