Remove a random expression from string

后端 未结 7 1645
春和景丽
春和景丽 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:11

    The Java solution given by @Kent above is very elegant and I recommend it. That said, if you want to accomplish this using Oracle's regex engine, you might try the following:

    WITH t1 AS (
        SELECT '000003023_AggregateStopLossLimit_W x3A 973911_2012-12-22.PDF' AS filename
          FROM dual
    )
    SELECT filename, REGEXP_REPLACE(filename, ' [^_]*', '')
      FROM t1
    

提交回复
热议问题