简体   繁体   中英

Replace White Spaces to “-” & uppercase to lower MySQL

I have 2 different field

name & slug

在此处输入图像描述

What I want to do is like for example on row #18

I have name value of Full Process Microbiological Analysis

and copied to slugs like this full-process-microbiological-analysis

As of now I can copy the value like this

 UPDATE services
 SET slug = name
 WHERE slug IS NULL OR slug = ""

But it only copy the value not modifying upper cases to lower cases and replacing whitespaces to dash(-)

Try this:

update services set
slug = replace(lower(name), ' ', '-')
where slug is null or slug = ''

See live demo :

select replace(lower('Full Process Microbiological Analysis'), ' ', '-')

returns

full-process-microbiological-analysis

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM