You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Oracle如何将(Ab56.12345)some_string格式的字符串列拆分为两列

Oracle括号前缀字符串拆分方案

直接通过正则捕获分组即可实现需求,完整实现代码如下:

with test (col) as
  (select '(Ab56.12345)some_string' from dual union all
   select 'another_string'          from dual union all
   select '(Xy99.88888)demo_text'   from dual
  )
select 
  regexp_substr(col, '^\((.*?)\)', 1, 1, null, 1) as col1,
  regexp_replace(col, '^\(.*?\)', '') as col2
from test;

运行结果

COL1COL2
Ab56.12345some_string
NULLanother_string
Xy99.88888demo_text

逻辑说明

  • regexp_substr 最后一个参数指定返回第一个捕获组的内容,正则^\((.*?\)匹配字符串开头左括号到第一个右括号之间的内容,匹配失败自动返回null,符合无括号前缀场景的要求
  • regexp_replace 直接删除开头的括号包裹前缀,不存在该前缀时返回原字符串,无需额外分支判断

内容的提问来源于stack exchange,提问作者Elsa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 13:06:00