Oracle从字符串中提取变量号
我希望从查询中长度可变的混合字母数字字符字符串中提取特定数字。我需要这个来计算基于该数字的范围。我正在使用甲骨文。
示例:
D-3-J32P232
- 我需要至少抓住 J32,甚至很可能抓住该字符串中的 32。这个数字范围可以在任何给定时间发生变化。
它的范围可以是:
D-3-J1P232 到 D-3-J322P2342
第二个和第三个字母后面的数字可以是任意长度。有什么办法可以做到这一点吗?
I'm looking to extract a specific number out of a string of mixed alphanumeric characters that are variable in length in a query. I will need this in order to calculate a range based off that number. I'm using Oracle.
Example:
D-3-J32P232
-I need to grab the J32 at least, and most likely even the 32 out of that string. This range of numbers can change at any given time.
It could range from:
D-3-J1P232
to
D-3-J322P2342
The numbers after the second and third letters can be any number of length. Is there any way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这更简单,可以获取范围内的两个数字
This is simpler and gets both the numbers for the range
REGEXP_SUBSTR 可以工作(11g 版本):
A测试示例数据:
这将接受任何大小写字母字符串,后跟破折号,后跟一个或多个数字,后跟破折号,后跟另一个任意大小写字母字符串,然后是您感兴趣的号码。
在 10g REGEXP_REPLACE 中,有点不太简单,因为他们直到 11g 才添加引用子表达式的功能:
您的示例数据:
REGEXP_SUBSTR could work (11g version):
A test of your sample data:
This will accept any case alpha string, followed by a dash, followed by one or more digits, followed by a dash, followed by another any case alpha string, then your number of interest.
In 10g REGEXP_REPLACE, it's bit less straightforward, as they did not add the ability to reference subexpressions until 11g:
Your sample data:
REGEXP_SUBSTR 可以完成这项工作
REGEXP_SUBSTR would do the job