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.

December 31st, 2008

OVERLAY (replace substring)

The OVERLAY function changes all characters to lower case. The embedded_string replaces the length in string starting at character position start. If length is not specified, then the embedded_string will replace all characters after start in string.
Format: OVERLAY(string PLACING embedded_string FROM start [FOR length])

Example:           OVERLAY('Dare to be creative' PLACING 'great' FROM 12)

Result: ‘Dare to be great’
> PostgreSQL supports OVERLAY.

> Access, DB2, MySQL, and SQL Server do not support OVERLAY. Instead they use REPLACE.

> Oracle does not support OVERLAY. Instead it uses REGEXP_REPLACE.

December 30th, 2008

LOWER (chg. to lower case)

The LOWER function changes all characters to lower case. Case changes affect only letters. Spaces, numbers, special characters, and punctuation remain unchanged.
Format: LOWER(string)

Example:           LOWER('Look at THAT!')

Result: ‘look at that!’
> Access does not support LOWER. Instead it uses LCASE.

> DB2, and MySQL, support LOWER as well as LCASE.

> Oracle, PostgreSQL, and SQL Server support LOWER.

« Previous PageNext Page »