Search code examples
sqlstringdb2substr

How to substring from a certian index to the end in SQL


I want to get the substring from e.g. START=3 to the end of the string.

Str
stringExample
anotherStringExample

I need something like this:

SUBSTR(str, 3, `**end**`)

and the output should be:

Str
ringExample
otherStringExample

Solution

  • You can try this query

    select SUBSTR(Str,3,LENGTH(Str)-3+1) as Str;
    

    or

    select SUBSTR(Str,3) as Str;
    

    substr function w3schools link