如何从 MySQL 列中获取前 N 个字符
使用 SUBSTRING() 从 MySQL 列获取前 N 个字符。我们首先创建一个表 -
mysql>create table DemoTable ( Information text ); Query OK, 0 rows affected (2.63 sec)
使用插入命令在表中插入记录 -
mysql>insert into DemoTable values('MySQL is a structured query language');
Query OK, 1 row affected (0.13 sec)以下是使用 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)
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP