Hi guys,
I am trying to do an alphabetical sequence using sql query with 5 characters.
I am stuck on this query. Can you help me to get a sequence between AAAAA to ZZZZZ ?
Thank you
select * from(
select i1,i2,i3,i4,i5,l,
case when i5 > 0 then chr(i5+ascii('A')-1) end ||
case when i4 > 0 then chr(i4+ascii('A')-1) end ||
case when i3 > 0 then chr(i3+ascii('A')-1) end ||
case when i2 > 0 then chr(i2+ascii('A')-1) end ||
chr(i1+ascii('A')-1)
str
from (
select mod((level-1),27) i1,
mod( trunc((level-0.1)/27),27) i2,
mod( trunc((level-0.1)/27/27),27) i3,
mod( trunc((level-0.1)/27/27/27),27) i4,
mod( trunc((level-0.1)/27/27/27),27) i5, -- even if 4x /27 is not working
level l
from dual
connect by level <= 40000
)
where i1 <> 0
and NOT( l>= 27*27 and i2 = 0)
and NOT( l>= 27*27*27 and i3 = 0)
and NOT( l>= 27*27*27*27 and i4 = 0)
and NOT( l>= 27*27*27*27*27 and i5 = 0)
order by i1,i2,i3,i4,i5)
where
--length(str) = 5 and
str = 'AAZZZ'
order by i5,i4,i3,i2,i1,l;