What is STRCMP() in SQL?
The STRCMP() function compares two strings sent as a parameter.
Figure 1 shows a visual representation of the STRCMP() function.
Syntax
STRCMP(str1, str2)
Parameter
The STRCMP() function takes two strings as a parameter.
Return value
The STRCMP() function compares two strings sent as a parameter.
- If both the strings are equal, then this function returns 0.
- If string-1 > string-2, then this function returns 1.
- If string-1 < string-2, then this function returns -1.
- If any of the strings is NULL, then this function returns NULL.
Code
-- Both the strings are sameSELECT STRCMP('educative','educative');-- string-1 < string-2SELECT STRCMP('edpresso','educative');-- string-1 > string-2SELECT STRCMP('educative','edpresso');-- string-1 = NULLSELECT STRCMP(NULL,'edpresso');