使用 LIKE (SQL) 连接表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5224907/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Joining tables with LIKE (SQL)
提问by Jacob Nelson
First of all I am using Oracle:
首先,我使用的是 Oracle:
Table One Name = tableone
表一名称 = tableone
Table Two Name = tabletwo
表二名称 = tabletwo
tableone
has a column named pizzaone
, tabletwo
has a column named pizzatwo
. I want to join tableone
to tabletwo
where pizzaone
is somewhere in the pizzatwo
's name.
tableone
有一列名为pizzaone
,tabletwo
有一列名为pizzatwo
。我想加入tableone
到tabletwo
其中,pizzaone
是在某个地方pizzatwo
的名字。
What I tried:
我试过的:
select * from tableone join tabletwo on tableone.pizzaone like ('%' + tabletwo.pizzatwo + '%')
How can I correct this query?
如何更正此查询?
回答by DCookie
Try this syntax instead:
试试这个语法:
select *
from tableone
join tabletwo on tableone.pizzaone like ('%' || tabletwo.pizzatwo || '%')
Oracle's string concatenation operator is the double pipe (||). The invalid number error is because Oracle expects numeric operands for the '+' operator.
Oracle 的字符串连接运算符是双管道 (||)。无效数字错误是因为 Oracle 需要“+”运算符的数字操作数。