Open In App

STRCMP() and SPACE() in MariaDB

Last Updated : 07 Dec, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

1. STRCMP() :
In MariaDB, STRCMP() Function tests whether two strings are the same using the current character set. In this function, the first parameter will be the string1 and the second parameter will be string2. If both strings will be same it will return 0, if the first string is greater than the second string then it will return 1, If the second string is greater than first string then it will return -1.

Syntax :

STRCMP( string1, string2 )

Parameter :

String1, string2 –The two strings to be compared to each other.

Return :
It will return 1, 0, -1.

Example-1 :

SELECT STRCMP
('geeksforgeeks', 'geeksforgeeks');

Output :

0

Example-2 :

SELECT STRCMP('DSA', 'DBMS');

Output :

1

Example-3 :

SELECT STRCMP('Article', 'Post');

Output :

-1

2. SPACE() Function :
In MariaDB, SPACE() function returns a string with a specified number of spaces. In this function, the first parameter will be the number. It will return that number of spaces in the result. If the number is negative or 0 it will return no space.

Syntax :

SPACE( number )

Parameter :
Number –
The number of spaces to be returned.

Return :
It will return a string with a given number space.

Example-1 :

SELECT SPACE(3);

Output :

'   '

Example-2 :

SELECT SPACE(0);

Output :

''

Example-3 :

SELECT SPACE(-5);

Output :

''

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads