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

    Stellar Converter for Database Tool

    MySQL /

    Stellar Converter for Database

    Stellar MySQL Log Analyzer

    MySQL /

    Stellar Log Analyzer for MySQL

    Stellar Repair for MySQL

    MySQL /

    Stellar Repair for MySQL

    MySQL /

    How to secure your SQL Database: Tips and Tricks

    Stellar Converter for Database

    MySQL /

    Database Converter Tools

    ‹ Transaction ACID Properties› MySQL CONCAT Function

    Recent Posts

    • Running Tests in Parallel with Selenium Grid
    • Advanced Selenium Features
    • Locating Web Elements
    • Running the Test Script
    • Writing Your First Selenium Test Script
    • Getting Started with Selenium Automation Testing
    • Setting Up the Environment
    • How can you monitor the Quality Assurance Audit?
    • Leveraging LambdaTest with Appium 2.0
    • Appium 2.0 Plugins ListAppium 2.0 Plugins
    • Touch Actions and Multi-Touch Actions
    • Changes in Drivers and Classes
    • Appium Inspector
    • Capabilities in Appium 2.0
    • Appium 2.0 Driver ListAppium 2.0 Driver Installation & Management
    CyberLink Multimedia Software

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com