VeloDB Cloud
SQL Reference
SQL Functions
Scalar Functions
String Functions
STRCMP

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

ParameterDescription
<str0>The first string to compare. Type: VARCHAR
<str1>The second string to compare. Type: VARCHAR

Return Value

Returns a TINYINT value 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

  1. Comparing identical strings
SELECT strcmp('test', 'test');
+------------------------+
| strcmp('test', 'test') |
+------------------------+
|                      0 |
+------------------------+
  1. First string is greater
SELECT strcmp('test1', 'test');
+-------------------------+
| strcmp('test1', 'test') |
+-------------------------+
|                       1 |
+-------------------------+
  1. First string is smaller
SELECT strcmp('test', 'test1');
+-------------------------+
| strcmp('test', 'test1') |
+-------------------------+
|                      -1 |
+-------------------------+