作為問題,
如何將一個字串列分成(Ab56.12345)some_string兩列Ab56.12345,并some_string在Oracle中?
注意:并非所有列都是(Ab56.12345)some_string,只有部分列some_string沒有(Ab56.12345),兩列是null和some string
@Littlefoot 的這個答案現在無法解決我的問題
SQL> with test (col) as
2 (select '(12345)some_string' from dual union all
3 select 'another_string' from dual
4 )
5 select regexp_substr(col, '\d ') col1,
6 substr(col, instr(col, ')') 1) col2
7 from test;
```
COL1 COL2
------------------ ------------------
12345 some_string
another_string
uj5u.com熱心網友回復:
我們可以REGEXP_SUBSTR在此處與捕獲組一起使用:
SELECT
REGEXP_SUBSTR(col, '\((. ?)\)', 1, 1, NULL, 1) AS COL1,
REGEXP_REPLACE(col, '\(. ?\)', '') AS COL2
FROM test;

演示
uj5u.com熱心網友回復:
或者,不使用正則運算式,使用substr instr組合:
SQL> WITH test(col) AS (
2 SELECT '(12345)some_string' FROM dual UNION ALL
3 SELECT 'another_string' FROM dual UNION ALL
4 SELECT '(Ab56.12345)string' FROM dual
5 )
6 SELECT
7 replace(replace(substr(col, 1, instr(col, ')')), '(', ''), ')', '') col1,
8 substr(col, instr(col, ')') 1) col2
9 FROM test;
COL1 COL2
------------------ ------------------
12345 some_string
another_string
Ab56.12345 string
SQL>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/336356.html
標籤:甲骨文
上一篇:我們可以使用SQL更新來更新CLOB列的html資料嗎?
下一篇:從oracle表中洗掉特定行
