sql - 使用正则表达式在列中查找和追加
问题描述
我有一张名为 test 的表。我需要使用正则表达式查找任何字母并在名称列中附加 ALL。请需要您的意见。
注意:将来的值也将插入该列。所以在运行时它应该替换。
create table test(id number, name varchar2(10));
insert INTO TEST VALUES (1,'_A');
insert INTO TEST VALUES (2,'_F');
insert INTO TEST VALUES (3,'_K');
insert INTO TEST VALUES (4,'_B || _G');
我的输出应该如下所示
-------------------------------
id column
--------------------------------
1 _AALL
2 _FALL
3 _KALL
4 _BALL || _GALL
解决方案
您可以使用regexp_replace
with test as(
select 1 as id , '_A' as l from dual union all
select 1 as id , '_B || _G' as l from dual
)
select t.*
, trim(regexp_replace(t.l,'(_[A-Z])( |$)','\1'||'ALL '))
from test t
推荐阅读
- grep - 从命令行搜索 Jupyter 笔记本降价单元格
- python - 如何从字符串创建函数(Python3)
- java - 如何在nodelist中将xml解析为java
- visual-studio - 关闭所有,但固定和这个?
- java - PowerMockito 验证永远不会调用静态方法
- grails - 如何通过模拟对象并期待一些预期结果来编写 Spock 单元测试
- corda - 我们应该如何升级一个由一个 DL 参与者拥有但有一个包含多个参与者的参与者列表的状态?
- ruby - 数组意外多重赋值
- continuous-integration - CircleCI:ESLint 在 CI 上返回退出代码 0 尽管测试失败
- javascript - 如果从数据库中获取的数据是!=“Detained”,如何调用函数