Tuesday, March 28, 2006

The smart way of coding

I had an requirement like
":,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,"

i have to replace the first : with 1 and the second : with 2 and it goes on.....

the solution for that was

select max(sys_connect_by_path(l,',')) from
(select level l
from dual
connect by level <= length(replace(':,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,:,',',')))
start with l=1
connect by l = prior l+1

could have done this way , it would have been better.
i was forced to type manually , LOL [reason : to make sure it is correct.]
it sucks, always.. use ur skills instead of manual service.
for that only we have been hired ;)

1 comments:

Anonymous said...

Clever use of level generation and sys_connect_by_path...

copied ur query and made some changes

select sys_connect_by_path(l,',') from
(select level l
from dual
connect by level <= length(':,:,:,:,:,:,:,')/2)
where l=length(':,:,:,:,:,:,:,')/2
start with l=1
connect by l = prior l+1