Mid Function In Sql in SQL
MID Function in SQL
The MID() function extracts a substring from a given string, starting at a specified position for a specified length.
? Syntax:
MID(string, start_position, length)string: The original string.start_position: The starting position (1-based index).length: Number of characters to extract.
? Example:
SELECT MID('Hello World', 7, 5) AS substring;Result:
| substring |
|---|
| World |
? Notes:
MID()is synonymous withSUBSTRING()in MySQL.In some databases (like SQL Server and Oracle), use
SUBSTRING()instead.If
lengthexceeds the string length, it returns until the end of the string.
Equivalent in other SQL dialects:
MySQL:
MID()orSUBSTRING()SQL Server:
SUBSTRING()Oracle:
SUBSTR()
If you want, I can show examples with SUBSTRING() or SUBSTR() too!