2016-07-05 103 views
0

我的數據可能看起來像這樣如何從一個字符串中提取特定數量

Goods Receipt required for document 5105250265 from Vendor 
Goods Receipt(s) have been fully taken for document 5105295587 
Goods Receipt required for document 5105285525 from Vendor 
Please process Vendor invoice from CARDIFF COUNTY COUNC, reference 1801314625 
Goods Receipt required for document 5105302265 from Vendor 

我想提取的號碼以5,總是10位。

提取此數字的最佳方法是什麼?

最好能想出是

select regexp_replace(column, '[A-Za-z]') from table 

但這並不檢查數量與5個或10位數

回答

2

假設你已經開始至多一個數量符合標準您可以嘗試以下操作:

with test (text) as 
(
select 'Goods Receipt required for document 5105250265 from Vendor' from dual union all 
select 'Goods Receipt(s) have been fully taken for document 5105295587' from dual union all 
select 'Goods Receipt required for document 5105285525 from Vendor' from dual union all 
select 'Please process Vendor invoice from CARDIFF COUNTY COUNC, reference 1801314625' from dual union all 
select 'Goods Receipt required for document 5105302265 from Vendor' from dual 
) 
select regexp_substr(text, '5[0-9]{9}') 
from test 
+0

完美!非常感謝你。 – totalitarian

相關問題