Problem: Given a string, find whether its a palindrome or not by SQL query.
Solution:
select decode(count(distinct ascii(straight.ch)-ascii(revers.ch)),1,'YES','NO') is_palindrome
from
(select ch,rownum rownumber
from
(
select substr(name,level,1) ch,rownum rn from
(
select &palindrome name from dual
)
connect by prior name=name
and level<=length(name)
and prior dbms_random.string('p',10) is not null
)) straight,
(select ch,rownum rownumber
from
(
select ch
from
(
select substr(name,level,1) ch,rownum rn from
(
select &palindrome name from dual
)
connect by prior name=name
and level<=length(name)
and prior dbms_random.string('p',10) is not null
)
order by rn desc
)
) revers
where straight.rownumber=revers.rownumber
sqlite3
-
I just tried sqlite. It is ultra-light and support SQL commands. Just try
this $ sqlite3 test.db SQLite version 3.26.0 2018-12-01 12:34:55 Enter
".help" fo...
3 weeks ago
1 comment:
This can also be done using
SELECT DECODE('&enter',REVERSE('&enter'),'Y','N') FROM DUAL
Cheers
Kartik
Post a Comment