How number values be used as arguments in MySQL STRCMP() function?


For the purpose of comparison, we can use number values as an argument in STRCMP() function. They are given as arguments without quotes. Following example will demonstrate it.

Example

mysql> Select STRCMP(10,10)As 'Equal Numbers', STRCMP(11,10)AS '2nd Smaller', STRCMP(10,11)AS '1st Smaller', STRCMP(10,NULL)As '2nd NULL',STRCMP(NULL,10)AS '1st NULL',STRCMP(NULL,NULL)AS 'Both NULL';
+---------------+-------------+-------------+----------+----------+-----------+
| Equal Numbers | 2nd Smaller | 1st Smaller | 2nd NULL | 1st NULL | Both NULL |
+---------------+-------------+-------------+----------+----------+-----------+
| 0             | 1           | -1          | NULL     | NULL     | NULL      |
+---------------+-------------+-------------+----------+----------+-----------+
1 row in set (0.00 sec)

Updated on: 10-Feb-2020

84 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements