如何从MySQL列获取前N个字符?
用于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)
热门推荐
10 新人红包祝福语简短精辟
11 幼师给毕业祝福语简短
12 生日高考祝福语妹妹简短
13 下飞机祝福语简短英文
14 元宵发客户祝福语简短
15 爸妈金婚文案祝福语简短
16 新郎朋友红包祝福语简短
17 虎年五一祝福语大全简短
18 出阁宴祝福语姐姐简短