如何在mysql中删除前导和尾部斜杠

时间:2012-06-01 03:24:39

标签: mysql sql trim

我需要在表格菜单中查询删除/来自url字段

原始表

menuname url
home     /home/
about    /home/about/

要求

menuname   url
home       home
about      home/about

3 个答案:

答案 0 :(得分:11)

这是从字段中删除尾部斜杠的方法:

UPDATE `table_name` SET `field_name`=TRIM(TRAILING '/' FROM `field_name`)

答案 1 :(得分:7)

SELECT TRIM( BOTH  '/'    FROM  '/bar/' )     

修改

SELECT TRIM(BOTH  '/' FROM link ) FROM menu

答案 2 :(得分:3)

请参阅http://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_trim

示例:

SELECT TRIM(BOTH '/' FROM home, about) FROM 'table_name';