- カテゴリ:
文字列とバイナリ関数 (一般)
CONCAT , ||
¶
1つ以上の文字列を連結するか、1つ以上のバイナリ値を連結します。値のいずれかがNullの場合、結果もNullになります。
||
演算子は CONCAT の代替構文を提供し、少なくとも2つの引数が必要です。
- See also:
構文¶
CONCAT( <expr1> [ , <exprN> ... ] )
<expr1> || <expr2> [ || <exprN> ... ]
Returns¶
The data type of the returned value is the same as the data type of the input value(s).
照合の詳細¶
The collation specifications of all input arguments must be compatible.
The collation of the result of the function is the highest-precedence collation of the inputs.
例¶
2つの文字列を連結します。
SELECT CONCAT('George Washington ', 'Carver'); +----------------------------------------+ | CONCAT('GEORGE WASHINGTON ', 'CARVER') | |----------------------------------------| | George Washington Carver | +----------------------------------------+
2つの VARCHAR 列を連結します。
CREATE TABLE table1 (s1 VARCHAR, s2 VARCHAR, s3 VARCHAR); INSERT INTO table1 (s1, s2, s3) VALUES ('ye', 't', 'i'), ('Colorado ', 'River ', NULL);SELECT CONCAT(s1, s2) FROM table1; +-----------------+ | CONCAT(S1, S2) | |-----------------| | yet | | Colorado River | +-----------------+
3つ以上の文字列を連結します。
SELECT CONCAT(s1, s2, s3) FROM table1; +--------------------+ | CONCAT(S1, S2, S3) | |--------------------| | yeti | | NULL | +--------------------+
関数の代わりに連結演算子「||」を使用します。
SELECT 'This ' || 'is ' || 'another ' || 'concatenation ' || 'technique.'; +--------------------------------------------------------------------+ | 'THIS ' || 'IS ' || 'ANOTHER ' || 'CONCATENATION ' || 'TECHNIQUE.' | |--------------------------------------------------------------------| | This is another concatenation technique. | +--------------------------------------------------------------------+