Oracle获取日期格式为两个日期之间的字符串 [英] Oracle get date formatted as string between two dates

查看:136
本文介绍了Oracle获取日期格式为两个日期之间的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用2个格式化日期,如果我有TO_DATE('20160101'YYMMDD)和TO_DATE('20160104',YYMMDD),我想收到此输出:

I am trying to work with 2 formatted dates, if I have TO_DATE('20160101' YYMMDD) and TO_DATE('20160104', YYMMDD) I would like to receive this output:

20160101
20160102
20160103
20160104

是否有一种无需使用PL/SQL即可快速实现这一目标的方法?

Is there a fast way to achieve this without using PL/SQL?

谢谢大家!

推荐答案

to_date()中的格式掩码也必须用单引号引起来.

The format mask in to_date() must be enclosed within single quotes too.

要生成字符串格式的输出,您需要应用具有相同格式掩码的to_char().

To produce the output in string format you need to apply to_char() with the same format mask.

select to_char(to_date('20160101', 'YYYYMMDD') + level - 1, 'YYYYMMDD') as dt
from   dual
connect by level <= 1 + to_date('20160104', 'YYYYMMDD') - to_date('20160101', 'YYYYMMDD')
;


DT     
--------
20160101
20160102
20160103
20160104

这篇关于Oracle获取日期格式为两个日期之间的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆