如何从oracle中的列中提取子字符串?
How to extract a substring from column in oracle?
我在 oracle 中有一列将值存储在键中。举个例子-
Column_name
((key1="value1" AND key2='value1') OR (key1="value1" AND key2='value2'))
((key1="null" AND key2='value3') OR (key1="value1" AND key2='value4'))
我只想提取 OR 子句之前的 key2 的值(因为此列的每一行都有 2 个 key2)
预期结果:
Column_name
Value
((key1="value1" AND key2='value1') OR (key1="value1" AND key2='value2'))
value1
((key1="null" AND key2='value3') OR (key1="value1" AND key2='value4'))
value3
有人可以大致告诉我怎么做吗?
假设我们可以将您的逻辑描述为提取 first key2
值,我们可以尝试将 REGEXP_SUBSTR
与捕获组一起使用:
SELECT col, REGEXP_SUBSTR(col, 'key2=''(.*?)''', 1, 1, NULL, 1) AS key
FROM yourTable;
我在 oracle 中有一列将值存储在键中。举个例子-
Column_name |
---|
((key1="value1" AND key2='value1') OR (key1="value1" AND key2='value2')) |
((key1="null" AND key2='value3') OR (key1="value1" AND key2='value4')) |
我只想提取 OR 子句之前的 key2 的值(因为此列的每一行都有 2 个 key2)
预期结果:
Column_name | Value |
---|---|
((key1="value1" AND key2='value1') OR (key1="value1" AND key2='value2')) | value1 |
((key1="null" AND key2='value3') OR (key1="value1" AND key2='value4')) | value3 |
有人可以大致告诉我怎么做吗?
假设我们可以将您的逻辑描述为提取 first key2
值,我们可以尝试将 REGEXP_SUBSTR
与捕获组一起使用:
SELECT col, REGEXP_SUBSTR(col, 'key2=''(.*?)''', 1, 1, NULL, 1) AS key
FROM yourTable;