如何在 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)
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP