检索MySQL中文本字段的前40个字符?
要从文本字段中获取前40个字符,请使用LEFT()MySQL中的function。语法如下-
SELECT LEFT(yourColumnName,40) as anyVariableName from yourTableName;
为了理解上述概念,让我们创建一个表。创建表的查询如下-
mysql> create table retrieveFirst40Characters −> ( −> AllWords text −> );
现在,您可以借助insert命令在表中插入一些记录。查询如下-
mysql> insert into retrieveFirst40Characters values('This is a query demo to extract a forty characters from a text
'> field,you can use left function to get forty characters');使用select语句显示表中的所有记录。查询如下-
mysql> select *from retrieveFirst40Characters;
以下是输出-
+------------------------------------------------------------------------------------------------------------------------+ | AllWords | +------------------------------------------------------------------------------------------------------------------------+ | This is a demo text displayed in a table for our example | +------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
这是从文本字段中提取前40个字符的查询-
mysql> select left(AllWords,40) as Retrieve40Characters from retrieveFirst40Characters;
以下是显示前40个字符的输出-
+------------------------------------------+ | Retrieve40Characters | +------------------------------------------+ | This is a demo text displayed in a table | +------------------------------------------+ 1 row in set (0.03 sec)
热门推荐
10 香港老妈结婚祝福语简短
11 毕业立体贺卡祝福语简短
12 简短新年年会祝福语
13 评论小品祝福语大全简短
14 恭喜师兄结婚祝福语简短
15 员工集体辞职祝福语简短
16 高中新生祝福语 简短
17 装修祝福语男生搞笑简短
18 生日开业蛋糕祝福语简短