【发布时间】:2019-12-04 23:26:12
【问题描述】:
select regexp_replace('home care','home care','care') as column1,
regexp_replace('home care','home care','home') as column2
from WORDLIST w
输出:
column1 column2
care home
然后
select regexp_replace('care home','care home','home') as column3,
regexp_replace('care home','care home','care') as column4
from WORDLIST w
输出:
column3 column4
home care
所以现在我想通过将一个 select 语句嵌套到另一个没有“join”字且也没有 where 子句的 select 语句来将这两个正则表达式连接在一起,输出应该如下:
column1 column2 column3 column4
care home home care
如果有任何建议,我将不胜感激!
【问题讨论】:
-
为什么从
WORDLIST表中选择而不使用呢?无论如何,select regexp_replace('home care','home care','care') as column1, regexp_replace('home care','home care','home') as column2, regexp_replace('care home','care home','home') as column3, regexp_replace('care home','care home','care') as column4 from WORDLIST w会得到你想要的……我不明白为什么会想要这些。也许你只是给我们举了一个可怕的例子? -
@JNevill 是的,这就是我在这里寻求帮助的原因,我正在学习正则表达式。首先,我需要为四列分配别名,并将其中一列嵌套到另一列(连接操作),并且没有 where 子句,没有“连接”字样。所以我现在真的很困惑。有没有办法做到这一点?
-
我的意思是......你的问题没有多大意义。为什么要从
WORDLIST表中选择?您可以从dual中选择并获得相同的结果(或任何具有单个记录的表),因此这是多余的。您有两个SELECT语句从同一个表中选择,因此不需要连接,只需将一个SELECT子句中的列添加到另一个SELECT子句中,就像我在之前的评论中所做的那样。无需嵌套、连接或任何其他魔法。