將字串連線到具有 MySQL TEXT 資料型別的已建立欄位值集中


為此,請使用 CONCAT()。我們先建立一個表 -

mysql> create table DemoTable644 (Title text);
Query OK, 0 rows affected (0.81 sec)

使用插入命令在表中插入一些記錄 -

mysql> insert into DemoTable644 values('Introduction');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable644 values('Welcome in course');
Query OK, 1 row affected (0.10 sec)

使用 select 語句顯示錶中的所有記錄 -

mysql> select *from DemoTable644;

這將生成以下輸出 -

+-------------------+
| Title             |
+-------------------+
| Introduction      |
| Welcome in course |
+-------------------+
2 rows in set (0.00 sec)

這是連線文字資料型別中字串的查詢 -

mysql> update DemoTable644 set Title=concat(Title,' To MySQL');
Query OK, 2 rows affected (0.10 sec)
Rows matched: 2 Changed: 2 Warnings: 0

讓我們再次檢查表記錄 -

mysql> select *from DemoTable644;

這將生成以下輸出 -

+----------------------------+
| Title                      |
+----------------------------+
| Introduction To MySQL      |
| Welcome in course To MySQL |
+----------------------------+
2 rows in set (0.00 sec)

更新於:23-8-2019

132 人檢視

開啟您的 職業生涯

完成課程獲得認證

開始學習
廣告
© . All rights reserved.