MySQL 如何仅显示200个字符
您可以使用MySQL中的LEFT()来从整个值中显示一些字符。以下是语法:
select left(yourColumnName ,200 ) AS anyAliasName from yourTableName;
让我们首先创建一个表:
mysql> create table DemoTable (Paragraph longtext);
Query OK, 0 rows affected (0.71 sec)
以下是使用插入命令将记录插入表中的查询:
mysql> insert into DemoTable values('Introduction to Java,Introduction to C,Introduction to
C++,Introduction to Spring,Introduction to Hibernate,Introduction to Python,Introduction to
MySQL,Introduction to MongoDB,Introduction to SQL Server,Introduction to
ASP.net,Introduction to JSF');
Query OK, 1 row affected (0.13 sec)
以下是使用select命令从表中显示记录的查询:
mysql> select *from DemoTable;
这将产生以下输出:
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Paragraph |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Introduction to Java,Introduction to C,Introduction to C++,Introduction to Spring,Introduction to Hibernate,Introduction to Python,Introduction to MySQL,Introduction to MongoDB,Introduction to SQL Server,Introduction to ASP.net,Introduction to JSF |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
以下是从总值中仅显示200个字符的查询:
mysql> select left(Paragraph ,200) AS `200Characters` from DemoTable;
这将产生以下输出,仅显示前200个字符:
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 200Characters |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Introduction to Java,Introduction to C,Introduction to C++,Introduction to Spring,Introduction to Hibernate,Introduction to Python,Introduction to MySQL,Introduction to MongoDB,Introduction to SQL Ser |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
阅读更多:MySQL 教程