sql - 如何在oracle sql查询中提取括号之间的文本
问题描述
我正在尝试从字符串中提取括号之间的值。
例如,我有这个字符串:
No information was found [AI1234].
我想得到括号之间的结果,即AI1234
.
然而,表达方式并不总是相同的。它可能会有所不同。
我正在尝试编写这样的查询:
REGEXP_SUBSTR(mssg, '\((.+)\)', 1, 1, NULL, 1) AS "description" from book
但它没有返回任何东西。我错过了什么?
我也已经尝试过类似的方法,问题是支架长度可能会有所不同。所以下面这个会返回一些东西,但不是我要找的东西:
substr(mssg,instr(mssg,'(')-8,10) as "description"
解决方案
如果您正在寻找方括号之间的一组数字,请尝试以下操作:
WITH
indata(msg) AS (
SELECT 'No information was found [1234]'
)
SELECT
REGEXP_SUBSTR(
msg -- the string
, '^[^[]+[[](\d+)[]].*$' -- the pattern (with a captured
-- string "\d+" in round parentheses)
, 1 -- start from position 1
, 1 -- first found occurrence
, '' -- no modifiers
, 1 -- first captured group
) AS extr
FROM indata;
extr
------
1234
推荐阅读
- java - Javafx:文本字段处理程序
- python - 仅在 Django Rest Framework 中验证
- python - 有没有更快的方法从 pyspark/python 中的 s3 读取数据
- r - 抓取功能仅适用于某些计算机 (R)
- python-3.x - Pygame 不会在 python 3.8 中导入
- debugging - 如何为内核调试设置 GDB 以查看串行端口活动?
- java - Java 中的单调函数的 Comparables
- python - 如何通过按下按钮更新标签文本
- svg - 如何使用 elm-ui 在 elm 中显示圆形图像?
- javascript - 量角器在尝试在 Linux 上的 Chrome 上运行时出错(Erro do Protractor otentar executar no Chrome no Linux)