How do string functions and concatenation differ between SQL databases?
How do string functions and concatenation differ between SQL databases?
String basics are standard, but concatenation, length and splitting differ between engines and cause most porting bugs.
| Database | Operator / function | NULL behaviour |
|---|---|---|
| SQL standard, PostgreSQL, Oracle, SQLite | `a | |
| MySQL | CONCAT(a, b); ` |
|
| SQL Server | a + b or CONCAT(a, b) |
+ gives NULL; CONCAT treats NULL as empty |
| PostgreSQL | CONCAT(a, b) also exists |
skips NULL |
CONCAT_WS(sep, a, b, c) (MySQL, PostgreSQL, SQL Server 2017+) joins with a separator and skips NULLs.
SELECT CONCAT_WS(' ', first_name, middle_name, last_name) AS full_name FROM people;
| Task | Standard / PostgreSQL | MySQL | SQL Server | Oracle |
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.