Thursday, July 3, 2008

substr [Oracle SQL]

substr(string, position)
substr(string, position, length)
The position parameter indicates where the substring starts. It's not zero indexed, that is, in order to start with the fourth character, the parameter has to be 4:
select substr('1234567890',4) from dual;
However, if the position parameter is 0, it is treated like being 1:
select substr('1234567890',0, 3) from dual;
select substr('1234567890',1, 3) from dual;
The parameter can also be negative, in which case it is counted from the right side:
select substr('1234567890',-4,3) from dual;

No comments: