Oracle 11:SQL:246バイト(ちょっと、少なくともJavaに勝っています:P笑)
with d as(select to_date('&1','yyyy-mm-dd')s,to_date('&2','yyyy-mm-dd')e from dual),r as(select level-1 l from d connect by level<=e-s+1),x as(select s+l y,to_char(s+l,'yyyymmdd')w from d,r)select to_char(y,'yyyy-mm-dd')from x where w=reverse(w);
出力:
SQL> with d as(select to_date('&1','yyyy-mm-dd')s,to_date('&2','yyyy-mm-dd')e from dual),r as(select level-1 l from d connect by level<=e-s+1),x as(select s+l y,to_char(s+l,'yyyymmdd')w from d,r)select to_char(y,'yyyy-mm-dd')from x where w=reverse(w);
Enter value for 1: 2000-01-01
Enter value for 2: 2021-01-01
TO_CHAR(Y,
----------
2001-10-02
2010-01-02
2011-11-02
2020-02-02
SQL>
読み取り可能な形式:
with d as (select to_date('&1','yyyy-mm-dd') s,
to_date('&2','yyyy-mm-dd') e
from dual),
r as (select level-1 l
from d connect by level <= e-s+1),
x as (select s+l y, to_char(s+l,'yyyymmdd') w
from d,r)
select to_char(y,'yyyy-mm-dd')
from x
where w=reverse(w);
説明:
d: get input for start/end
r: generate rows needed, 1 per day.
x: calculate the actual dates, and convert them to a minimal string.
final: use REVERSE function to verify the palindroms, return in proper format.
今日、リバース機能について学びました:)
DATE
を使用して回避to_date()
できVARCHAR2
ますか?