MySQL STRCMP Function
MySQL STRCMP Function
In this tutorial, we will learn about MySQL STRCMP function with an example. STRCMP() function is a string comparison function. We can use this function to compare strings.
The STRCMP() function returns 0 as result if the strings are the same, -1 if the first argument is smaller than the second argument according to the sort order, and 1 otherwise.
Syntax
The general syntax of the function is as follows:
STRCMP(strarg1,strarg2)
Examples
mysql> SELECT STRCMP(‘Testing’,’Testing’);
+—————————–+
| STRCMP(‘Testing’,’Testing’) |
+—————————–+
| 0 |
+—————————–+
1 row in set (0.02 sec)
mysql> SELECT STRCMP(‘Testing’,’testing’);
+—————————–+
| STRCMP(‘Testing’,’testing’) |
+—————————–+
| 0 |
+—————————–+
1 row in set (0.00 sec)
mysql> SELECT STRCMP(‘Testing’,’Testing2′);
+——————————+
| STRCMP(‘Testing’,’Testing2′) |
+——————————+
| -1 |
+——————————+
1 row in set (0.00 sec)
mysql> SELECT STRCMP(‘Testing2′,’Testing’);
+——————————+
| STRCMP(‘Testing2′,’Testing’) |
+——————————+
| 1 |
+——————————+
1 row in set (0.00 sec)
—
MySQL Tutorials
MySQL Tutorials on this website:
https://www.testingdocs.com/mysql-tutorials-for-beginners/
For more information on MySQL Database: