Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
180 views
in Technique[技术] by (71.8m points)

Oracle get date formatted as string between two dates

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

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

Thanks to all!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...