在mysql替换中将/替换为_

在mysql替换中将/替换为_

问题描述:

我有一个小代码,允许我将自定义名称从现有字段添加到新字段,但它不会将/(斜线)删除为 _(下划线).

I have a small code that allows me to add custom name to a new field from an existing field but it does not remove / (slash) to _ (underscore).

UPDATE `custom` SET custom_url = LOWER(REPLACE(REPLACE(REPLACE(Name, ' ', '_'), '(', ''), ')', ''));

我怎样才能重写这段代码,让它也允许我这样做?

How can I re-write this code so that it also allows me to do that?

正斜杠在 MySQL 中没有特殊含义,只需添加一个额外的替换即可.

Forward slashes have no special meaning in MySQL, just add an extra replace.

UPDATE `custom` 
SET custom_url = LOWER(
                   REPLACE(
                     REPLACE(
                       REPLACE(
                         REPLACE(Name, ' ', '_')
                       , '(', '')
                     , ')', '')
                   ,'/','_')
                 );

如果您想删除 / 则将 ,'/','_') 替换为 ,'/','')> 在底部替换部分.

If you want to remove the / then replace ,'/','_') with ,'/','') in the bottom replace part.