如何從 MySQL 列中獲取前 N 個字元
使用 SUBSTRING() 從 MySQL 列獲取前 N 個字元。我們首先建立一個表 -
mysql>create table DemoTable ( Information text ); Query OK, 0 rows affected (2.63 sec)
使用插入命令在表中插入記錄 -
mysql>insert into DemoTable values('MySQL is a structured query language');
Query OK, 1 row affected (0.13 sec)以下是使用 select 語句從表中顯示所有記錄的查詢 -
mysql>select *from DemoTable;
這會產生以下輸出 -
+--------------------------------------+ | Information | +--------------------------------------+ | MySQL is a structured query language | +--------------------------------------+ 1 row in set (0.00 sec)
這是從列中獲取前 N 個字元的查詢。在本例中,我們選擇了前 10 個字元 -
mysql>select substring(Information,1,10) from DemoTable;
這會產生以下輸出 -
+-----------------------------+ | substring(Information,1,10) | +-----------------------------+ | MySQL is a | +-----------------------------+ 1 row in set (0.00 sec)
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP