我正在从包含以下值的oracle表(使用sql)中进行选择:
ae0.32767
bcm0.0
em0.0
ge-0/1/0.32767
ge-7/1/0.100
ge-7/1/0.32767
lo0.0
lsi.0
pc-0/0/0.16383
pc-1/0/0.16383
pc-5/0/0.16383
xe-0/0/0.838 如何提取小数点后的值(使用regexp)而不包括小数点。
例如:
32767
0
0
32767
100
32767
0
0
16383
16383
16383
838 发布于 2012-11-14 14:42:03
regexp_substr函数可用于提取字符串末尾的句点后的数字。下面是一个示例:
-- sample of data from your question
SQL> with t1 as (
2 select 'ae0.32767' as col from dual union all
3 select 'bcm0.0' from dual union all
4 select 'em0.0' from dual union all
5 select 'ge-0/1/0.32767' from dual union all
6 select 'ge-7/1/0.100' from dual union all
7 select 'ge-7/1/0.32767' from dual union all
8 select 'lo0.0' from dual union all
9 select 'lsi.0' from dual union all
10 select 'pc-0/0/0.16383' from dual union all
11 select 'pc-1/0/0.16383' from dual union all
12 select 'pc-5/0/0.16383' from dual union all
13 select 'xe-0/0/0.838' from dual
14 )
15 select regexp_substr(col, '(\.)([[:digit:]]+)$', 1,1,'i',2) res
16 from t1
17 ;
RES
--------------------------------------------------------
32767
0
0
32767
100
32767
0
0
16383
16383
16383
838
12 rows selected发布于 2012-11-14 14:42:06
尝试使用substr和instr来获得所需的输出,如下所示
SELECT SUBSTR ('ge-0/1/0.32767',
INSTR ('ge-0/1/0.32767', '.') + 1,
LENGTH ('ge-0/1/0.32767') - INSTR ('ge-0/1/0.32767', '.')
)
FROM DUAL SQL Fiddle Demo
发布于 2012-11-14 14:10:42
你没有提到编程语言。通常,此正则表达式匹配小数点后的数字:
\.(?<wanted>\d+)您可以从匹配结果中删除初始点,或者如果您的语言支持命名组捕获(例如,C#支持),您可以使用\1、$1或名为"wanted"的组来捕获这些数字。
https://stackoverflow.com/questions/13373838
复制相似问题