我有一个字符串,可能是以下类型
string          expected result
15-th-rp         15
15/12-rp         12
15-12-th         12
4-5-6            5
现在我必须找到数字,1)如果一个字符串只包含1digit,那么将显示相同的数字.2)如果字符之间有多组数字,那么我必须找到第二组数字.请帮我.
  with a as (
   select '15-th-rp' as data from dual
   union all
   select  '15/12-rp' from dual
   union all
   select  '15-12-th' from dual
   union  all
   select '4-5-6' from dual
  )
  select regexp_substr(data,'[0-9]+',REGEXP_INSTR(data,'[/|-]')+1) from a;
我想这就是你所追求的:
with a as (select '15-th-rp' data from dual union all
           select '15/12-rp' data from dual union all
           select '15-12-th' data from dual union all
           select '4-5-6' data from dual)
select data,
       coalesce(regexp_substr(data,'[0-9]+',1,2),
                regexp_substr(data,'[0-9]+',1,1)) extracted_data
from   a;
DATA     EXTRACTED_DATA
-------- --------------
15-th-rp 15            
15/12-rp 12            
15-12-th 12            
4-5-6    5     
使用COALESCE的好处是它不会评估第二个(和后续的)参数,除非它们是必需的.