STRCMP() FUNCTION in MySQL

STRCMP() FUNCTION The MySQL STRCMP function is used to compare two strings. The various versions of MySQL support the STRCMP function, namely, MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0 and MySQL 3.23.

Syntax:

STRCMP( string1, string2 )

Parameters: string1, string2: It is used to specify the strings to compare.

Example 1:

mysql> SELECT STRCMP ( ‘abc’,  ‘abc’ );

Output:

0

Explanation: The STRCMP function returns 0 if the two strings are the same.

Example 2:

mysql> SELECT STRCMP ( ‘abc’,  ‘xyz’ );

Output:

-1

Explanation: The STRCMP function returns -1 if string1 < string2.

Example 3:

mysql> SELECT STRCMP ( ‘xyz’,  ‘abc’ );

Output:

1

Explanation: The STRCMP function returns 1 if string1 > string2.

Please follow and like us:
Content Protection by DMCA.com