little tips and tricks, which i stumbled upon randomly

Wednesday, April 11, 2012

Oracle style LTRIM / RTRIM for SYBASE IQ

Oracle's LTRIM/RTRIM supports second parameter to remove other characters than blank.
For example
select LTRIM('My Textaaaa', 'a') from dual; will return 'My Text'.
Same behavior can be simulated with Sybase IQ as well

LTRIM:
substr(<STRING>, length(<STRING>)-length(ltrim(replace( <STRING> ,<CHARACTERS TO REMOVE>,' ')))+1)

RTRIM:
substr( <STRING> ,1,length(rtrim(replace( <STRING> , <CHARACTERS TO REMOVE> ,' '))))

0 comments:

Post a Comment