如何在 MySQL 中仅显示总值中的 200 个字符?
你可以使用 MySQL 中的 LEFT() 函数在 MySQL 中显示全部值的某些字符。以下是语法
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)
以下查询使用选择命令从表中显示记录
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)
广告