在mysql替换中将/替换为_ [英] Replace / to _ in mysql replace

查看:61
本文介绍了在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.

这篇关于在mysql替换中将/替换为_的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆