位置:首頁 > 數據庫 > MySQL教學 > MySQL strcmp()函數

MySQL strcmp()函數

STRCMP(str1, str2)

比較兩個字符串,如果這兩個字符串相等返回0,如果第一個參數是根據當前的排序小於第二個參數順序返回-1,否則返回1。

mysql> SELECT STRCMP('MOHD', 'MOHD');
+---------------------------------------------------------+
| STRCMP('MOHD', 'MOHD')                                  |
+---------------------------------------------------------+
| 0                                                       |
+---------------------------------------------------------+
1 row in set (0.00 sec)

另一個例子是:

mysql> SELECT STRCMP('AMOHD', 'MOHD');
+---------------------------------------------------------+
| STRCMP('AMOHD', 'MOHD')                                 |
+---------------------------------------------------------+
| -1                                                      |
+---------------------------------------------------------+
1 row in set (0.00 sec)

讓我們來看看一個例子:

mysql> SELECT STRCMP('MOHD', 'AMOHD');
+---------------------------------------------------------+
| STRCMP('MOHD', 'AMOHD')                                 |
+---------------------------------------------------------+
| 1                                                       |
+---------------------------------------------------------+
1 row in set (0.00 sec)