MariaDB: MID Function
This MariaDB tutorial explains how to use the MariaDB MID function with syntax and examples.
Description
The MariaDB MID function allows you to extract a substring from a string.
Syntax
The syntax for the MID function in MariaDB is:
MID( string, start_position, length )
Parameters or Arguments
- string
- The source string.
- start_position
- The position for extraction. The first position in the string is always 1.
- length
- The number of characters to extract.
Note
- The first position in string is 1.
- If start_position is a positive number, then the MID function starts from the beginning of the string.
- If start_position is a negative number, then the MID function starts from the end of the string and counts backwards.
- The MID function and the SUBSTR function are synonyms of the SUBSTRING function.
Applies To
The MID function can be used in the following versions of MariaDB:
- MariaDB 10
Example
Let's look at some MariaDB MID function examples and explore how to use the MID function in MariaDB.
For example:
SELECT MID('TechOnTheNet.com', 1, 4); Result: 'Tech' SELECT MID('TechOnTheNet.com', 5, 8); Result: 'OnTheNet' SELECT MID('TechOnTheNet.com', -3, 3); Result: 'com' SELECT MID('TechOnTheNet.com', -10, 6); Result: 'TheNet'
Advertisements