作為問題,
如何將一個字串列分成(12345)some_string兩列12345,并some_string在Oracle中?
注意:并非所有列都是(12345)some_string,只有部分列some_string沒有(12345),兩列是null和some string
uj5u.com熱心網友回復:
假設下表:
create table my_table (my_column varchar2(30));
insert into my_table values ('(12345)some_string');
commit;
1)在表中添加一個新列
alter table my_table add new_column number;`
2)填寫新列
update my_table set new_column = regexp_substr(my_column, '^\(([1-9] )\)', 1, 1, NULL, 1);
3)更新原列
update my_table set my_column = regexp_replace(my_column, '^\([1-9] \)', '');
uj5u.com熱心網友回復:
使用您發布的示例資料,這可能是一種選擇(從第 5 行開始):
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
SQL>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/333129.html
標籤:甲骨文
下一篇:查詢以考慮具有優先級的分組的型別
