STRCMP() mengembalikan 0 jika stringnya sama, -1 jika argumen pertama lebih kecil dari argumen kedua berdasarkan urutan pengurutan saat ini, dan NULL jika salah satu argumennya NULL. Ia mengembalikan 1 sebaliknya.
SELECT STRCMP('text', 'text2');
-1
SELECT STRCMP('text2', 'text');
1
SELECT STRCMP('text', 'text');
0
STRCMP() performs the comparison using the collation of the arguments.
SELECT STRCMP('text', 'text2');
-1
SELECT STRCMP('text2', 'text');
1
SELECT STRCMP('text', 'text');
0
If the collations are incompatible, one of the arguments must be converted to be compatible with the other. See Section 12.8.4, “Collation Coercibility in Expressions”.
SET @s1 = _utf8mb4 'x' COLLATE utf8mb4_0900_ai_ci;
SET @s2 = _utf8mb4 'X' COLLATE utf8mb4_0900_ai_ci;
SET @s3 = _utf8mb4 'x' COLLATE utf8mb4_0900_as_cs;
SET @s4 = _utf8mb4 'X' COLLATE utf8mb4_0900_as_cs;
SELECT STRCMP(@s1, @s2), STRCMP(@s3, @s4);
+------------------+------------------+
| STRCMP(@s1, @s2) | STRCMP(@s3, @s4) |
+------------------+------------------+
| 0 | -1 |
+------------------+------------------+
SET @s1 = _utf8mb4 'x' COLLATE utf8mb4_0900_ai_ci;
SET @s2 = _utf8mb4 'X' COLLATE utf8mb4_0900_ai_ci;
SET @s3 = _utf8mb4 'x' COLLATE utf8mb4_0900_as_cs;
SET @s4 = _utf8mb4 'X' COLLATE utf8mb4_0900_as_cs;
-->
SELECT STRCMP(@s1, @s3);
ERROR 1267 (HY000): Illegal mix of collations (utf8mb4_0900_ai_ci,IMPLICIT)
and (utf8mb4_0900_as_cs,IMPLICIT) for operation 'strcmp'
SELECT STRCMP(@s1, @s3 COLLATE utf8mb4_0900_ai_ci);
+---------------------------------------------+
| STRCMP(@s1, @s3 COLLATE utf8mb4_0900_ai_ci) |
+---------------------------------------------+
| 0 |
+---------------------------------------------+