Orcale查询日期字段的数据方法教程

转换为字符串类型进行比较

to_char()

select * from table where to_char(a,’yyyy-mm-dd’)=’2018-06-26′ ;

yyyy-mm-dd是日期的格式,可以自己定义 ,只要和后面要查询的值匹配上即可。

select * from cbcj_qc t where to_char(t.zxrq,'yyyy-mm-dd')='2018-06-15';   --转换为字符串进行比较

转换为日期类型进行比较

to_date()

select * from table where a=to_date(‘20180626′,’yyyymmdd’);

yyyy-mm-dd是日期的格式,可以自己定义 ,只要和前面要查询的值匹配上即可。

select * from cbcj_qc t where t.zxrq=to_date('2018-06-15','yyyy-mm-dd');   --如数据库中字段默认精确到秒,会查询不到

select * from cbcj_qc t where t.zxrq=to_date('2018-06-15 18:30:24','yyyy-mm-dd hh24:mi:ss');  --精确到分秒的要把格式带上才可以查询

--查询“税收缴款期限”字段值在2018-06-25与2018-06-26之间的数据
select * from cbcj_qc_qy t where t.ssjkqx between to_date('2018-06-25','yyyy-mm-dd') and to_date('2018-06-26','yyyy-mm-dd'); 
(0)
上一篇 2022年3月22日
下一篇 2022年3月22日

相关推荐