假設(shè)如果一個(gè)表中有許多值在表的列中包含空格,那么這是浪費(fèi)空間。我們可以使用 TRIM() 函數(shù)從所有行中刪除空格并在單個(gè)查詢中更新表。按照“Employee”的示例,所有行中都有空格將展示這一概念 –
示例
mysql> Select * from Employee; +------+----------------------+----------------------+----------------------+ | Id | Name | Address | Department | +------+----------------------+----------------------+----------------------+ | 100 | Raman | Delhi | IT | | 101 | Mohan | Haryana | History | | 102 | Shyam | Chandigarh | ENGLISH | | 103 | Sukhjeet Singh | Patiala | Computer Engg. | | 104 | Bimal Roy | Calcutta | Computer Engg. | +------+----------------------+----------------------+----------------------+ 5 rows in set (0.00 sec)
登錄后復(fù)制
從上面的結(jié)果集中我們可以看到,Employee 表的行中有很多空格。可以使用以下查詢刪除和更新它 –
mysql> Update Employee SET Id = TRIM(Id), Name = TRIM(Name), Address = TRIM(Address), DEPARTMENT = TRIM(Department); Query OK, 5 rows affected (0.24 sec) Rows matched: 5 Changed: 5 Warnings: 0 mysql> Select * from Employee; +------+----------------+------------+----------------+ | Id | Name | Address | Department | +------+----------------+------------+----------------+ | 100 | Raman | Delhi | IT | | 101 | Mohan | Haryana | History | | 102 | Shyam | Chandigarh | ENGLISH | | 103 | Sukhjeet Singh | Patiala | Computer Engg. | | 104 | Bimal Roy | Calcutta | Computer Engg. | +------+----------------+------------+----------------+ 5 rows in set (0.00 sec)
登錄后復(fù)制
從上面的結(jié)果集中可以看到,所有的空格都被刪除了,表格也被更新了。
以上就是我們?nèi)绾问褂?MySQL TRIM() 刪除所有行中的空格并更新表?的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注www.92cms.cn其它相關(guān)文章!