栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 数据库 > Oracle

oracle查询截至到当前日期月份所在年份的所有月份

Oracle 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

oracle查询截至到当前日期月份所在年份的所有月份

下面通过一个查询语句给大家介绍oracle查询截至到当前日期月份所在年份的所有月份,具体代码如下所示:

SELECt to_number(TO_CHAr(add_months(trunc(sysdate, 'yy'), ROWNUM - 1), 'MM')) as month
 FROM DUAL
ConNECT BY ROWNUM <=
 (select months_between(trunc(sysdate, 'mm'), trunc(sysdate, 'yy')) + 1
 from dual);

当然,也可以指定具体的时间段,只要把months_between里面的两个日期改成具体的日期就行,

其中,trunc(sysdate, 'mm')是返回当月的第一天,trunc(sysdate, 'yy')是返回当年的第一天。

扩展知识点 Oracle trunc()函数的用法


select trunc(sysdate) from dual --2013-01-06 今天的日期为2013-01-06
select trunc(sysdate, 'mm') from dual --2013-01-01 返回当月第一天.
select trunc(sysdate,'yy') from dual --2013-01-01 返回当年第一天
select trunc(sysdate,'dd') from dual --2013-01-06 返回当前年月日
select trunc(sysdate,'yyyy') from dual --2013-01-01 返回当年第一天
select trunc(sysdate,'d') from dual --2013-01-06 (星期天)返回当前星期的第一天
select trunc(sysdate, 'hh') from dual --2013-01-06 17:00:00 当前时间为17:35 
select trunc(sysdate, 'mi') from dual --2013-01-06 17:35:00 TRUNC()函数没有秒的精确


select trunc(123.458) from dual --123
.select trunc(123.458,0) from dual --123
.select trunc(123.458,1) from dual --123.4
.select trunc(123.458,-1) from dual --120
.select trunc(123.458,-4) from dual --0
.select trunc(123.458,4) from dual --123.458
.select trunc(123) from dual --123
.select trunc(123,1) from dual --123
.select trunc(123,-1) from dual --120

总结

以上所述是小编给大家介绍的oracle查询截至到当前日期月份所在年份的所有月份,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对考高分网网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/171087.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号