简体   繁体   English

如何在Oracle SQL中使用REGEX检索十进制后的特定字符?

[英]How to retrieve specific chars after decimal using REGEX in Oracle SQL?

I'm using RegEx in a View in Oracle 11g and I need to display certain codes that have an 'S' in the 8th position. 我在Oracle 11g的View中使用RegEx,并且需要显示某些在第8位带有“ S”的代码。

Using https://regexr.com/2v41h , 使用https://regexr.com/2v41h

I was able to display these results with REGEXP_SUBSTR(code, '\\S{8}') Y38.9X2S Y38.9X2D Y38.9X2A Y38.9X1S 我能够使用REGEXP_SUBSTR(code, '\\S{8}') Y38.9X2S Y38.9X2D Y38.9X2A Y38.9X1S显示这些结果

My issue is that I need to return only the values that have an 'S' in the last position which is the 8th position counting the decimal. 我的问题是,我只需要返回最后一个位置具有“ S”的值,该位​​置是计算小数点的第8个位置。 What expression should I use? 我应该使用什么表情?

Example: Y38.9X2S Y38.9X1S 示例: Y38.9X2S Y38.9X1S

I have tried: REGEXP_SUBSTR(code, '\\b[S]*[8]\\b') AS CODE 我已经尝试过: REGEXP_SUBSTR(code, '\\b[S]*[8]\\b') AS CODE

Thank you in advance for your help. 预先感谢您的帮助。

I am thinking: 我在想:

select substr(code, -8)
from t
where code like '%_______S'

If the code is always long enough, just use '%S' . 如果代码总是足够长,只需使用'%S'

Or, as a case expression: 或者,作为一个case表达:

select (case when code like '%_______S' then substr(code, -8) end)

You will need regular expressions if code has other characters but they may not be necessary. 如果code包含其他字符,则将需要正则表达式,但是可能不需要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM