Create Excerpts with Substring

To create smaller strings from larger piece of text you can use the SUBSTR() funciton or the substring function.

SELECT SUBSTR(<value or column>, <start>, <length>) FROM <table>;
  • \ : Specifies where to start in the string

    • if is 0 (zero), then it is treated as 1.

    • if is positive, then the function counts from the beginning of string to find the first character.

    • if is negative, then the function counts backward from the end of string.

  • \ : length of the desired substring

SELECT SUBSTR('abcdefg', 3,4);

OUTPUT: cdef

SELECT SUBSTR('abcdefg', -5,4);

OUTPUT: cdef

Last updated

Was this helpful?