January 2nd, 2009

SUBSTRING (get part of string)

The SUBSTRING function allows a shorter string to be extracted from a longer string. The result is extracted from the source_string, starting in position, start_position (an integer value), for the number of characters, length (an integer value, if specified). The COLLATE clause forces the result set into another pre-existing collating sequence.

Format: SUBSTRING(source_string FROM start_position [FOR length] [COLLATE name])

Example:           SUBSTRING('My name is William Diamond' FROM 12)

Result: ‘William Diamond’

> If the input string is NULL, then the result will be NULL.
> Access does not support SUBSTRING. Instead it uses MID(string, start [, length]) and SPLIT.
> DB2 does not support SUBSTRING. Instead it uses SUBSTR(string, start [, length]).
> MySQL uses only SUBSTRING(source_string FROM start_position) and assumes that the substring will be from the start_position to the end of the string.
> Oracle does not support SUBSTRING. It uses SUBSTR(string, start [, length]). If a negative number is entered for start, then Oracle counts backwards from the end of the string. With a negative start and with no length, it extracts all the way to the beginning. Oracle treats an empty string as NULL. SUBSTR(NULL, 1, 1) results in ‘ ‘ (an empty string).
> PostgreSQL supports SUBSTRING, but does not support COLLATE.
> SQL Server supports SUBSTRING(string, start, length), but does not support COLLATE.

2 Responses to ' SUBSTRING (get part of string) '

Subscribe to comments with RSS or TrackBack to ' SUBSTRING (get part of string) '.

  1. on September 14th, 2009 at 10:39 pm

    Hello, I found your blog in a new directory of blogs. I dont know how your blog came up, must have been a typo, Your blog looks good. Have a nice day.

  2. on February 15th, 2010 at 10:50 pm

    I like the way you think. Would you consider sharing more of the idea you presented?

Leave a reply

:mrgreen: :neutral: :twisted: :shock: :smile: :???: :cool: :evil: :grin: :oops: :razz: :roll: :wink: :cry: :eek: :lol: :mad: :sad: