SQL MID() 函数

SQL 教程 · 2019-03-04 10:13:19

MID() 函数

MID() 函数用于从文本字段中提取字符。

SQL MID() 语法

SELECT MID(column_name,start[,length]) FROM table_name;

参数 描述
column_name 必需。要提取字符的字段。
start 必需。规定开始位置(起始值是 1)。
length 可选。要返回的字符数。如果省略,则 MID() 函数返回剩余文本。

演示数据库

在本教程中,我们将使用 CODERCTO 样本数据库。

下面是选自 "Websites" 表的数据:

+----+--------------+---------------------------+-------+---------+
| id | name         | url                       | alexa | country |
+----+--------------+---------------------------+-------+---------+
| 1  | Google       | https://www.google.cm/    | 1     | USA     |
| 2  | 淘宝          | https://www.taobao.com/   | 13    | CN      |
| 3  | 码农教程      | http://www.codercto.com/    | 4689  | CN      |
| 4  | 微博          | http://weibo.com/         | 20    | CN      |
| 5  | Facebook     | https://www.facebook.com/ | 3     | USA     |
| 7  | stackoverflow | http://stackoverflow.com/ |   0 | IND     |
+----+---------------+---------------------------+-------+---------+

SQL MID() 实例

下面的 SQL 语句从 "Websites" 表的 "name" 列中提取前 4 个字符:

实例

SELECT MID(name,1,4) AS ShortTitle
FROM Websites;

点击查看所有 SQL 教程 文章: https://codercto.com/courses/l/29.html

查看所有标签

The Art and Science of CSS

The Art and Science of CSS

Jonathan Snooks、Steve Smith、Jina Bolton、Cameron Adams、David Johnson / SitePoint / March 9, 2007 / $39.95

Want to take your CSS designs to the next level? will show you how to create dozens of CSS-based Website components. You'll discover how to: # Format calendars, menus and table of contents usin......一起来看看 《The Art and Science of CSS》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具