SUBSTRING()

Documentation

Home » Documentation » Using VoltDB

SUBSTRING()

SUBSTRING() — Returns the specified portion of a string expression.

Synopsis

SUBSTRING( string-expression FROM position [TO length] )

SUBSTRING( string-expression, position [, length] )

Description

The SUBSTRING() function returns a specified portion of the string expression, where position specifies the starting position of the substring (starting at position 1) and length specifies the maximum length of the substring. The length of the returned substring is the lower of the remaining characters in the string expression or the value specified by length.

For example, if the string expression is "ABCDEF" and position is specified as 3, the substring starts with the character "C". If length is also specified as 3, the return value is "CDE". If, however, the length is specified as 5, only the remaining four characters "CDEF" are returned.

If length is not specified, the remainder of the string, starting from the specified by position, is returned. For example, SUBSTRING("ABCDEF",3) and SUBSTRING("ABCDEF"3,4) return the same value.

Example

The following example uses the SUBSTRING function to return the month of the year, which is a VARCHAR column, as a three letter abbreviation.

SELECT event, SUBSTRING(month,1,3), day, year FROM calendar
    ORDER BY event ASC;