While linking the strings, if I will add a NULL value then what would be the output of a CONCAT_WS() function?


Actually, CONCAT_WS() function returns NULL if and only if the first argument of it i.e. the separator is NULL. An example is as below −

mysql> Select CONCAT_ws(NULL,'Tutorial','Point','.com');
+-------------------------------------------+
| CONCAT_ws(NULL,'Tutorial','Point','.com') |
+-------------------------------------------+
| NULL                                      |
+-------------------------------------------+
1 row in set (0.00 sec)

Otherwise, MySQL CONCAT_WS() function ignores NULL if we place NULL at any other position in CONCAT_WS() function while linking the strings. Following examples will exhibit it −

mysql> Select CONCAT_ws('s','Tutorial','Point','.com',NULL);
+-----------------------------------------------+
| CONCAT_ws('s','Tutorial','Point','.com',NULL) |
+-----------------------------------------------+
| TutorialsPoints.com                           |
+-----------------------------------------------+
1 row in set (0.00 sec)

mysql> Select CONCAT_ws('s','Tutorial',NULL,'Point','.com');
+-----------------------------------------------+
| CONCAT_ws('s','Tutorial',NULL,'Point','.com') |
+-----------------------------------------------+
| TutorialsPoints.com                           |
+-----------------------------------------------+
1 row in set (0.00 sec)

Updated on: 22-Jun-2020

58 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements