您可以使用LEFT()
MySQL来显示MySQL整个值中的某些字符。以下是语法:
select left(yourColumnName ,200 ) AS anyAliasName from yourTableName;
让我们首先创建一个表:
mysql> create table DemoTable (Paragraph longtext);
以下是使用insert命令在表中插入记录的查询:
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');
以下是使用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)