Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

STRCMP() and SPACE() in MariaDB

  • Last Updated : 07 Dec, 2020

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 :

Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course  by GeeksforGeeks.

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 :

''
My Personal Notes arrow_drop_up
Recommended Articles
Page :