我有一个列名"value"在表T中有很长的错误描述,这里有几个
的例子但是它也抓取了我不需要的其他行
请帮忙吗?
这就回答了原来的问题。
要过滤行,使用regexp_like()
。我建议:
select t.*
from t
where regexp_like(value, '^An image has error at (1203|12345):')
我猜最后的冒号对匹配很重要。
为什么不能使用LIKE
操作符?
SELECT t.id, t.value, SUBSTR(t.value, 1, INSTR(t.value, ':')) short_value
FROM t
WHERE value LIKE 'An image has error at 1203:%'
OR value LIKE 'An image has error at 12345:%';
也许您的最佳选择似乎是标准substr+instr的组合,以提取所需的值,并使用regexp_like来确定整个字符串的可取性。
select substr(value, 1, instr(value, ':')-1 ) value
from d
where regexp_like (value,'An image has error at d+:');
尽管根据具体的测试要求和后面的数值可能只是
select substr(value, 1, instr(value, ':')-1 ) value
from d
where instr(value, ':') > 1;
最后,如果您愿意,您可以使用regexp_substr。然而,Oracle的语法对于正则表达式的使用是完全违反直觉的:
select value
from (select regexp_substr(value, '(.*):', 1, 1, 'i', 1) value
from d
)
where value is not null;
演示