VeloDB Cloud 26.x·Apache Doris 4.x (up to 4.0 supported)·"Since X.Y" tags refer to Apache Doris versionsVersion mapping
STRCMP
Description
The STRCMP function compares two strings lexicographically. It returns an integer value indicating the result of the comparison.
Syntax
STRCMP(<str0>, <str1>)
Parameters
| Parameter | Description |
|---|---|
<str0> | The first string to compare. Type: VARCHAR |
<str1> | The second string to compare. Type: VARCHAR |
Return Value
Returns TINYINT type, indicating the comparison result:
- Returns 0: if str0 equals str1
- Returns 1: if str0 is lexicographically greater than str1
- Returns -1: if str0 is lexicographically less than str1
Special cases:
- Returns NULL if any argument is NULL
Examples
- Identical string comparison
SELECT strcmp('test', 'test');
+------------------------+
| strcmp('test', 'test') |
+------------------------+
| 0 |
+------------------------+
- First string is greater
SELECT strcmp('test1', 'test');
+-------------------------+
| strcmp('test1', 'test') |
+-------------------------+
| 1 |
+-------------------------+
- First string is smaller
SELECT strcmp('test', 'test1');
+-------------------------+
| strcmp('test', 'test1') |
+-------------------------+
| -1 |
+-------------------------+
Keywords
STRCMP