用于SUBSTRING()从MySQL列中获取前N个字符。让我们首先创建一个表-mysql>create table DemoTable
(
Information text
);
使用插入命令在表中插入记录-mysql>insert into DemoTable values('MySQL is a structured query language');
以下是使用select语句显示表中所有记录的查询-mysql>select *from DemoTable;
这将产生以下输出-+--------------------------------------+
| Information |
+--------------------------------------+
| MySQL is a structured query language |
+--------------------------------------+
1 row in set (0.00 sec)
这是从列中获取前N个字符的查询。在这种情况下,我们选择前10个字符-mysql>select substring(Information,1,10) from DemoTable;
这将产生以下输出-+-----------------------------+
| substring(Information,1,10) |
+-----------------------------+
| MySQL is a |
+-----------------------------+
1 row in set (0.00 sec)
|