SQL CONCAT function
Joins strings into one. The trap is NULL: engines disagree on whether one NULL argument makes the whole result NULL, and the || operator can behave differently from CONCAT on the same engine.
- 카테고리
- Strings
- Returns
string- In this category
- 1 of 172
구문
CONCAT(a, b, ...)
a || b -- PostgreSQL, SQLite, Oracle, SQL Server 2025
Each block is a separate form. The support table and the examples show which engine takes which.
엔진 지원
| 엔진 | Support | 메모 |
|---|---|---|
| SQL Server | 예 | CONCAT from 2012; the || operator from SQL Server 2025 |
| PostgreSQL | 예 | Supported under this name. |
| MySQL | 예 | CONCAT returns NULL if any argument is NULL; || means OR unless PIPES_AS_CONCAT is set |
| SQLite | 예 | CONCAT and CONCAT_WS from SQLite 3.44; || has always existed |
| Oracle | 예 | CONCAT took exactly two arguments before 23ai; || ignores NULLs |
예시
Any engine
SELECT CONCAT(first_name, ' ', last_name) AS full_name FROM users;
PostgreSQL
-- || is stricter: NULL poisons the result SELECT NULL || 'a' AS strict_concat; -- NULL
MySQL
SELECT CONCAT_WS(', ', city, region, country) AS place
FROM addresses;
알아 두면 좋은 정보
- NULL handling differs by engine: CONCAT on SQL Server, PostgreSQL, SQLite and Oracle treats NULL as an empty string, but MySQL's CONCAT returns NULL if any argument is NULL.
- The || operator is stricter than CONCAT on PostgreSQL and SQLite: NULL || 'a' is NULL there. Oracle's || ignores NULL operands, so the same expression gives 'a'.
- On MySQL, || is logical OR by default: 'a' || 'b' returns 0. Use CONCAT, or set sql_mode PIPES_AS_CONCAT.
- CONCAT never adds separators. CONCAT_WS(', ', a, b, c) does, and skips NULL arguments; it exists on MySQL, PostgreSQL, SQL Server 2017+ and SQLite 3.44+.
Questions about CONCAT
Does CONCAT return NULL if a value is NULL?
Depends on the engine: SQL Server, PostgreSQL, SQLite and Oracle treat NULL as empty; MySQL returns NULL for the whole call. COALESCE each argument if the query has to behave the same everywhere.
What is the difference between CONCAT and ||?
On PostgreSQL and SQLite, NULL || x is NULL while CONCAT skips the NULL. On MySQL, || is logical OR unless PIPES_AS_CONCAT is set. Oracle's || ignores NULLs, and its CONCAT took only two arguments before 23ai. SQL Server only gained || in 2025.
How do I concatenate with a separator?
CONCAT_WS(', ', a, b, c) on MySQL, PostgreSQL, SQL Server 2017+ and SQLite 3.44+; it skips NULL arguments instead of leaving doubled separators. Oracle has no CONCAT_WS, so write a || ', ' || b. For values from many rows, use STRING_AGG.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
- String concatenation in SELECT: || vs + vs CONCAT Dialect comparison
- Concatenate a number to a string in SQL Server, PostgreSQL, MySQL, SQLite and Oracle Dialect comparison
- Anonymize email addresses in SQL Snippet
- Generate DROP TABLE statements Snippet
- Format money and currency values as strings in SQL Snippet
- Pad numbers with leading zeros in SQL Snippet
Cheat sheets for the engines that have it: SQL Server, MySQL, PostgreSQL, SQLite, Oracle.
Functions your engine actually has
SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.