截取数据库里以特定符号分割开的某个字段:sql(case when,substr,instr)的用法:

2022-09-10 08:47:32
select
    case
         when t.zone_type > 2 
    then 
          substr(t.full_name, instr(t.full_name, '_') + 1)
    else
          t.zone_name
from t_zone t

case 后面是条件

then 满足条件结果

else 不满足条件的结果

substr(String ,s):string:截取的字符串,s:从哪个位置开始截取到最后

instr:(String,s):s在String的哪个位置

上述sql意思:

full_name字段:江苏省_南京市_玄武区

最终得到的值:南京市_玄武区

  • 作者:bubu_1262278473
  • 原文链接:https://blog.csdn.net/weixin_45167765/article/details/121909239
    更新时间:2022-09-10 08:47:32