我有一个查询
select LOCATIONS.LOCATION, LOCATIONS.DESCRIPTION,
regexp_substr(LOCATIONS.DESCRIPTION, '[^,]+', 1, 2) AS col_one
from locations
where LOCATIONS.DESCRIPTION like 'SUB,%'
OR LOCATIONS.DESCRIPTION like 'STATION,%'
,结果如下
COL_ONE
--------------------
MONARCH SUBSTATION
PRICE SUBSTATION
DALLAS SUBSTATION
COLFAX STATION
BELMONT SUBSTATION
GREAT LAKES STEEL SUBST A
QUINCY SUBSTATION
FRENCH LANDING SUBSTATION
BERRY SUBSTATION DECOMMIS
MCLOUTH SUBSTATION A
MAZDA SUBSTATION
BARNES LAKE SUBSTATION
如何在列COL_ONE中删除单词Substation,SUBST以及这些单词后面的任何内容?
答案 0 :(得分:3)
考虑使用regexp_replace
。如果您正在尝试删除与regex
模式匹配的文字,这正是您所需要的:
示例强>
regexp_replace(LOCATIONS.DESCRIPTION, 'SUBST.*$', '')
<强>模式强>
。* - 匹配任何长度为零或以上的字符
$ - 指定字符串的结尾