sql - ORACLE - 从字符串中选择数字的表达式
问题描述
我有这张表,我需要选择字母“kV”或“KV”之前的数字。同样在最后一个示例中,el 编号在开头没有空格。
这里的例子:
select device_name from table;
--device_name can be:
15518 - 132 Garden Plain 138 kV l/o 0405 result 138
ALLENIM 345 KV ALL-RPM_I. result=345
179 BLOO345 KV TR84CT-P_I. result= 345. --on this case the number is withoutspace
我可以使用什么样的正则表达式来选择这些数字?
问候
解决方案
这是一种选择:在 upper 前面找到数字KV
,然后删除KV
:
SQL> with test (col) as
2 (select '15518 - 132 Garden Plain 138 kV l/o 0405' from dual union all-- result 138
3 select 'ALLENIM 345 KV ALL-RPM_I.' from dual union all-- result=345
4 select '179 BLOO345 KV TR84CT-P_I.' from dual -- result=345
5 )
6 select col,
7 replace(regexp_substr(upper(col), '\d+(\s?)KV'), 'KV', '') result
8 from test;
COL RESULT
---------------------------------------- --------------------
15518 - 132 Garden Plain 138 kV l/o 0405 138
ALLENIM 345 KV ALL-RPM_I. 345
179 BLOO345 KV TR84CT-P_I. 345
SQL>
推荐阅读
- reactjs - 电子反应逻辑
- ios - 任何 Scroll 事件(例如 onScroll)都不适用于 FlatList 组件
- html - 滑块句柄或两个并排 html 范围之间的颜色
- c# - 从 SQL Server 加载对象,但对 c# 类使用不同的对象属性
- cron - Ansible 是否支持评论 cron 作业
- constructor - 使用类构造函数编辑外部变量
- ios - 对象的外观不同取决于 iOS 中的设备
- jquery - 如何在 ionic 3 中使用引导模式?
- azure - 在 Azure API 管理中读取 FrontendRequest 消息内容错误
- qt - 使用 QTableview 中显示的 QSqlQueryModel 添加 CheckBox 其他列为空