我有一個像這樣的代碼:
SELECT config_id FROM config
哪個回傳我字串:
1S100I20C1P
1S8I9C1P
1S80I48C1P
我只需要獲取 S 和 I 之間的數字,對于 1 個字串,它將是 100,對于第二個字串,它將是 8 等。我知道 regexp 應該在這里作業,但無法真正找到匹配的模式。謝謝你。
uj5u.com熱心網友回復:
這實際上是該字串中的第二個數字( result1)。或者,使用substr instr組合 ( result2):
SQL> with config (config_id) as
2 (select '1S100I20C1P' from dual union all
3 select '1S8I9C1P' from dual union all
4 select '1S80I48C1P' from dual
5 )
6 select
7 config_id,
8 regexp_substr(config_id, '\d ', 1, 2) result1,
9 substr(config_id, instr(config_id, 'S') 1,
10 instr(config_id, 'I') - instr(config_id, 'S') - 1
11 ) result2
12 from config;
CONFIG_ID RESULT1 RESULT2
----------- ----------- -----------
1S100I20C1P 100 100
1S8I9C1P 8 8
1S80I48C1P 80 80
SQL>
uj5u.com熱心網友回復:
一種選擇是使用REGEXP_REPLACEwhich 包含字母S并I在模式內,例如
SELECT config_id,
REGEXP_REPLACE(config_id,'(.*S)(.*)(I.*)','\2') AS extractedString
FROM config
Demo
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/338227.html
