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
return code before grep
-
my 2009 solution return code before grep ( ( ( mycmd echo $? >&3 ) |grep
mytext >&4 ) 3>&1 |(read x;exit $x) )4>&1 my 2025 solution mycmd > >(grep
mytext)
1 week ago
1 comment:
This can also be done using
SELECT DECODE('&enter',REVERSE('&enter'),'Y','N') FROM DUAL
Cheers
Kartik
Post a Comment