CMP()
This page is part of MariaDB's Documentation.
The parent of this page is: Functions for MariaDB Xpand
Topics on this page:
Overview
Returns -1, 0, or 1 indicating the order of two values.
USAGE
CMP(value, value)
Argument Name | Description |
|---|---|
| The two values to compare |
DETAILS
CMP() is a function that returns -1, 0, or 1 to indicate the ordinality of two values.
If at least one argument is a number, a numeric comparison is performed. Thus, a string argument is converted into a number when paired with a numeric argument.
When both arguments are (non-NULL) strings, the result is the same as calling STRCMP(), including how the current sort order affects equality and ordinality.
The return value is 0 if the two arguments are equal.
The return value is -1 if the first argument sorts prior to the second.
The return value is 1 if the first argument sorts after the second.
A NULL argument sorts prior to any other non-NULL value. Two NULL arguments return 0 (equality).
EXAMPLES
SELECT CMP(99, 123),
STRCMP(99, 123);
+--------------+-----------------+
| CMP(99, 123) | STRCMP(99, 123) |
+--------------+-----------------+
| -1 | 1 |
+--------------+-----------------+
-- Disable strict mode or the select might throw an error
SET sql_mode = '';
SELECT CMP('abc', 0);
+---------------+
| CMP('abc', 0) |
+---------------+
| 0 |
+---------------+
SELECT CMP(5, NULL), CMP(NULL, NULL);
+--------------+-----------------+
| CMP(5, NULL) | CMP(NULL, NULL) |
+--------------+-----------------+
| 1 | 0 |
+--------------+-----------------+
