Remove a random expression from string

后端 未结 7 1649
春和景丽
春和景丽 2021-01-21 06:25

I have a string/column something like this

String a = \"000003023_AggregateStopLossLimit_W x3A 973911_2012-12-22.PDF\";

I want to create a subs

相关标签:
7条回答
  • 2021-01-21 07:23

    If you need a SQL solution, this will update the rows:

    update yourtable
    set field = substr(field, 0, instr(field, ' ')-1) || substr(field, instr(field, '_', instr(field, ' ')))
    ;
    

    and this will just show the converted value:

    select
      yourtable.field,
      case
        when instr(field, '_', instr(field, ' '))>instr(field, ' ')
        then substr(field, 0, instr(field, ' ')-1) || substr(field, instr(field, '_', instr(field, ' ')))
        else field
      end as new_field
    from
      yourtable
    
    0 讨论(0)
提交回复
热议问题