December 23rd, 2008

Concatenate || (attach values), Part 1 of 4

Two alphanumeric character values (or strings) can be attached together (concatenated) to form one value
(or a single string). We do this by using the concatenation symbol || which is two double-bar characters (two key strokes). Only string values can be concatenated.

Format: expression || expression

Example:      'Concat' || 'enation' -> becomes -> 'Concatenation'

> Concatenation does not add a space between the strings.
> Multiple concatenations may be performed. Such as ‘a’ || ‘b’ || ‘c’ becomes ‘abc’.
> Concatenation of an empty string adds nothing to the result. Such as ‘a’ || ” || ‘b’ || ” || ‘c’ becomes ‘abc’.
> If a NULL is used as a string, the result is a NULL. ‘a’ || NULL || ‘b’ || ‘c’ becomes NULL.
> You can concatenate hexadecimal and bit strings. Such as B’0000′ || B’1111′ becomes B’00001111′.
> If you wish to add a non-character value to a string, then that value must be converted to a character
string before the concatenation can be performed.
> The || can be used in SELECT, WHERE, and ORDER BY or anywhere an expression is allowed.
> Oracle treats a NULL as an empty string. Such as ‘Concat’ || NULL || ‘enation’ becomes ‘Concatenation’.
> In MySQL, the || symbol is illegal. MySQL uses CONCAT(). Such as CONCAT(’Concat’, ‘enation’).
> Access and SQL Server uses + between character strings for concatenation. Such as ‘Concat’ + ‘enation’.
> MySQL, Oracle, and PostgreSQL automatically convert non-string data to strings.

Leave a reply

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