
oracle中有张表year,month保存年月,这个结构如何按某个时间范围查询?
oracle中有张表year,month保存年月,这个结构如何按某个时间范围查询?
我来答
添加附件
收藏
分享
问题补充
3条回答
默认
最新
回答交流
Markdown
请输入正文
提交
问题信息
请登录之后查看
邀请回答
暂无人订阅该标签,敬请期待~~

oracle中有张表year,month保存年月,这个结构如何按某个时间范围查询?
假设你的年是4位字符,比如'2021';月是2位字符,比如'02'。如果要查询2021年1月到2021年5月,则
select * from tab where year||month between '202101' and '202105';
或者
select * from tab where to_date(year||month,'yyyymm') between date'2021-01-01' and date'2021-05-31';
where year||month between '202101' and '202105'; 最好对year||month建立函数索引。