Loading

MySQL String Functions Part-6

 RPAD Function:- RPAD Function is used for adding string on the right side of the original string.

Syntax:- RPAD(string, length, pad string)

For Example:-

SELECT RPAD(“kshtutor”, 13, “^”);

Output:- kshtutor^^^^^

SELECT RPAD(“kshtutor”, 12, “srkp”);

Output:- kshtutorsrkp

RTRIM Function:- RTRIM Function is used for removing the right side trailing space or white space from a string.

Syntax:-  RTRIM(string);

Example:- SELECT RTRIM(“KSH Tutor    “);

Output:- KSH Tutor

SPACE Function:- SPACE Function is used for specifying the number of empty space characters in a string..

Syntax:-  SPACE(number)

Example:-

SELECT CONCAT(‘KSH’, SPACE(15), ‘tutor’, SPACE(15), ‘blog’);

Output:- KSH tutor blog

STRCMP Function:- STRCMP Function is used for comparing two strings. If both strings will be the same then they will return zero. If the first string will be less than the second string then it will return -1 and if the first string will be greater than the second string then it will return 1.

Syntax:- STRCMP(string1, string2)

Example:-

SELECT STRCMP(“JS”, “PHP”);

Output:- -1

SELECT STRCMP(“php”, “html”);

Output:- 1

SELECT STRCMP(“php”, “php”);

Output:- 0

SUBSTR Function:- SUBSTR Function is used for extracting substring from a given string. SUBSTR Function and SUBSTRING Function both are the same or we can say they are synonyms.  SUBSTR Function and SUBSTRING Function are similar to MID Function.

Syntax:-

SUBSTR(string, start or position, length)

SUBSTRING (string, start or position, length)

For Example:-

SELECT SUBSTRING(“KSH Tutor”, 4, 6);

Output:- Tutor

SELECT SUBSTR(“KSH Tutor”, 4, 6);

Output:- Tutor

SUBSTRING_INDEX Function:- SUBSTRING_INDEX Function is used for return substring before a specified number of delimiter occurs. Delimiter will be case-sensitive.

Syntax:- SUBSTRING_INDEX(string, delimiter, number count)

For Example:-

SELECT SUBSTRING_INDEX(“www.kshtutor.com”, “.”, 2);

Output:- www.kshtutor

SELECT SUBSTRING_INDEX(“www.kshtutor.com”, “.”, -1);

Output:- com

TRIM Function:- TRIM Function is used for removing blank or trailing space on both sides of the string.

Syntax:- TRIM(string)

For Example:-

SELECT TRIM(”    KSH Tutor    “);

Output:- KSH Tutor

UCASE Function:- UCASE Function is used for converting strings in upper case or in block letters. UCASE Function and UPPER  Function both are the same or we can say both are synonyms.

Syntax:-

UCASE(string)

UPPER (string)

For Example:-

SELECT UCASE(“KSH tutor is nice”);

Output:- KSH TUTOR IS NICE

SELECT UPPER(“KSH tutor is nice”);

Output:- KSH TUTOR IS NICE

Share with:


Leave a Reply

Connect with:

z35W7z4v9z8w