sql - Oracle SQL:使用 REGEXP_SUBSTR 提取特定单词之前的文本
问题描述
使用 Oracle sql,我想提取某些单词之前的文本。我需要排除以“超过”或“最大”一词开头和之后的文本。
示例:“服用 1-2 个标签 4-6 小时。每天不要超过 5 个标签”
期望的输出:“服用 1-2 个标签 4-6 小时。不要”
解决方案
我通过使用 nested 实现了所需的输出regexp_substr()
,如下所示:
select trim(regexp_substr(
regexp_substr('Take 1-2 tabs 4-6 hours. Do not exceed 5 tabs per day','.*(exceed|max)'),
'.*[^(exceed|max)]'
)) desired_output
from dual;
但是,如果您需要“超出”或“最大”之前的空格,只需删除trim()
.
参考:https ://www.techonthenet.com/oracle/functions/regexp_substr.php
推荐阅读
- python-3.x - 我如何暂停一个线程,直到另一个线程停止它在 python 中的操作?
- google-cloud-sdk - 错误gcloud执行,重新安装后
- sql - 如何请求在房间中显示最新消息
- vue.js - Vue路由器无法识别View的子组件
- javascript - 没有参数的 Javasript 数组函数
- javascript - 谷歌地图 - addGeoJson 不适用于我的文件
- pandas - 更改图例的位置和条形图的大小
- c# - 为什么我在尝试使用 AddonSuccessListener 时收到 InvalidCastException?
- webhooks - FusionAuth:通过“设置密码”电子邮件确认时未触发 Webhook user.email.verified
- python-3.x - 将值作为 while 循环生成的行添加到 pd.dataframe