Mysql string Functions


Download 369.29 Kb.
bet7/8
Sana14.12.2022
Hajmi369.29 Kb.
#1001659
1   2   3   4   5   6   7   8
Bog'liq
MySQL String Functions

SPACE()


MySQL SPACE() returns the string containing a number of spaces as specified in the argument.
Example : SELECT 'start', SPACE(10), 'end';
Syntax : SPACE(N)
Output : start end SPACE(10)


SUBSTR()


MySQL SUBSTR() returns the specified number of characters from a particular position of a given string. SUBSTR() is a synonym for SUBSTRING().
Example : SELECT SUBSTR('w3resource',4,3);
Syntax : SUBSTR(str,pos,len)
Output : eso

SUBSTRING()


MySQL SUBSTRING() returns a specified number of characters from a particular position of a given string.
Example : SELECT SUBSTRING('w3resource',4,3);
Syntax : SUBSTRING(str,pos,len)
Output : eso

Example : SELECT SUBSTRING('w3resource.com',5);
Output : source.com

Example : SELECT SUBSTRING('w3resource.com',-5);
Output : e.com

SUBSTRING_INDEX()


MySQL SUBSTRING_INDEX() returns the substring from the given string before a specified number of occurrences of a delimiter.
Returns from the left of the final delimiter if the number is positive and right of the final delimiter when the number is negative.
If the number is greater than the number of occurrence of delimiter, the returned substring will be the total string. If the specified number is 0, nothing will be fetched from the given string.
Example : SELECT SUBSTRING_INDEX('www.mytestpage.info','.',2);
Syntax : SUBSTRING_INDEX(str,delim,count)
Output : www.mytestpage

TRIM()


MySQL TRIM() function returns a string after removing all prefixes or suffixes from the given string.
Example : SELECT TRIM(' trim ');
Syntax : TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str)
Output : trim (leading and trailing space removed)

Example : SELECT TRIM(LEADING 'leading' FROM 'leadingtext' );
Output : text

Example : SELECT TRIM(BOTH 'leadtrail' FROM 'leadtrailtextleadtrail');
Output : text


Download 369.29 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling