MySQL CASE语句和REGEXP [英] MySQL CASE statement and REGEXP

查看:148
本文介绍了MySQL CASE语句和REGEXP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用使用REGEXP的CASE语句.目前,我正在执行以下操作:

I want to use a CASE statement that uses REGEXP. Currently I am doing something like this:

SELECT NAME,
 CASE INFO
   WHEN 'not cool' THEN 'Not Cool'
   WHEN 'very cool' THEN 'Cool'
 ELSE INFO
 END AS INFO
FROM INFO_TABLE

是否可以在初始语句中使用REGEXP来使条件充当REGEXP?从理论上讲,这就是我想要的,这是行不通的:

Is there any way to use REGEXP in the initial statement to make the condition act as a REGEXP? In theory this is what I want, which doesn't work:

SELECT NAME,    
 CASE INFO REGEXP
   WHEN 'not cool' THEN 'Not Cool'
   WHEN 'very cool' THEN 'Cool'
 ELSE INFO
 END AS INFO
FROM INFO_TABLE

我希望不酷"和非常酷"成为正则表达式.希望这足够清楚.

I want 'not cool' and 'very cool' to be regular expressions. Hope that is clear enough.

推荐答案

尝试一下

select name,
case
  when info regexp 'not cool' then 'Not Cool'
  when info regexp 'very cool' then 'Cool'  
else 
  info
end 
  as info
from INFO_TABLE;

这篇关于MySQL CASE语句和REGEXP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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