TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

MySQL

MySQL String Functions

Overview

In this tutorial, we will learn about MySQL String Functions. There are many functions in MySQL that operate on strings.

MySQL String Functions

We can use string functions to calculate string length, concatenate strings, compare strings, extract sub strings of strings, search for sub strings, padding strings, trim strings, perform lowercase to uppercase conversion, etc.

String functions can be broadly divided into two categories: functions that return number and functions that return strings.  Some string functions are as follows:

 

MySQL String Function Description
CHAR_LENGTH(<string>) The function returns the number of characters in the given string.
INSTR(<string>, <sub-string>) The function returns the position in the string where the sub-string occurs, or 0 if the sub-string is not in the string
STRCMP(<string1>, <string2>) String Compare function
The function returns 0 if arguments are the same,-1 if string1 is smaller than string2, and 1 otherwise.
CONCAT(<arg1>, [,<arg2>….,  <argn>]) The function concatenates the given arguments into one string
REVERSE(<string>) The function returns the string with the characters in the reverse order
RIGHT(<string>, <length>) The function returns the rightmost length characters of string
LEFT(<string>, <length>) The function returns the leftmost length characters of string
LOWER(<string>) Returns string with all characters in the lowercase format
UPPER(<string>) Returns string with all characters in the uppercase format
LPAD(<string>, <length>, <padding>) The function returns the string left padded with padding until it reaches the length of characters.

 

RPAD(<string>, <length>, <padding>) The function returns the string right padded with padding until it reaches the length of characters.

 

TRIM ([[LEADING | TRAILING] <string> FROM ] <fullstring> The function removes the string characters at the end and/or beginning of the <fullstring> . When there is no argument after the <string> it returns <string> with all leading
and trailing spaces trimmed.
SUBSTRING (<string>, <startpos> [, <chars>]) The function returns the part of string starting at the position startpos and ending chars characters if specified, otherwise the function returns until the end of the string.
SUBSTRING_INDEX(<string>, <delimiter>, <count>) The function searches the string for the count occurrence of delimiter(from the left if count is positive, right if negative) and returns the characters searched through when reaching the count.

Examples

mysql> SELECT CONCAT(‘www.’,’Testing’,’Docs’,’.com’);
+—————————————-+
| CONCAT(‘www.’,’Testing’,’Docs’,’.com’) |
+—————————————-+
| www.TestingDocs.com |
+—————————————-+

mysql> SELECT REVERSE(‘TestingDocs.com’);
+—————————-+
| REVERSE(‘TestingDocs.com’) |
+—————————-+
| moc.scoDgnitseT |
+—————————-+

MySQL String Functions Examples

—

MySQL Tutorials

MySQL Tutorials on this website:

https://www.testingdocs.com/mysql-tutorials-for-beginners/

For more information on MySQL Database:

https://www.mysql.com/

Related Posts

DataGrip Desktop Shortcut

MySQL /

Launch DataGrip on Windows

DataGrip Download

MySQL /

Install DataGrip IDE on Windows 11

MySQL Workbench Windows 11

MySQL /

New MySQL Connection in Workbench

MySQL Command-line Client

MySQL /

Command-Line MySQL Client

Start MySQL Client

MySQL /

Start MySQL Client on Windows 11

‹ Transaction ACID Properties› MySQL CONCAT Function

Recent Posts

  • Update draw.io on Windows
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com