MySQL LTRIM()和RTRIM()函数如何与WHERE子句一起使用?
MySQLLTRIM()
和RTRIM()
函数可用于从表中的列值中消除前导和尾随空格。即使我们在WHERE子句中应用条件,这些函数也可以正常工作。
示例
mysql> Select LTRIM(Name) from Student; +-------------+ | LTRIM(Name) | +-------------+ | Gaurav | | Aarav | | Harshit | | Gaurav | | Yashraj | +-------------+ 5 rows in set (0.13 sec)
上面的查询从“名称”列的值中删除了前导空格字符。
mysql> Select RTRIM(Name) from Student; +-------------+ | RTRIM(Name) | +-------------+ | Gaurav | | Aarav | | Harshit | | Gaurav | | Yashraj | +-------------+ 5 rows in set (0.00 sec)
上面的查询从“名称”列的值中删除了结尾的空格字符。
mysql> Select LTRIM(Name) from Student Where Name = 'Harshit'; +-------------+ | LTRIM(Name) | +-------------+ | Harshit | +-------------+ 1 row in set (0.05 sec)
上面的查询从值中删除了前导空格字符,即在“名称”列的WHERE子句“Harshit”中给出的值。
mysql> Select RTRIM(Name) from Student Where Name = 'Gaurav'; +-------------+ | RTRIM(Name) | +-------------+ | Gaurav | | Gaurav | +-------------+ 2 rows in set (0.00 sec)
上面的查询从值(即在“名称”列的WHERE子句“Gaurav”中给出的值)中删除了尾随空格字符。