使用 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 09:36:47  来源:igfitidea点击:

Joining tables with LIKE (SQL)

sqloracleora-01722

提问by Jacob Nelson

First of all I am using Oracle:

首先,我使用的是 Oracle:

Table One Name = tableone

表一名称 = tableone

Table Two Name = tabletwo

表二名称 = tabletwo

tableonehas a column named pizzaone, tabletwohas a column named pizzatwo. I want to join tableoneto tabletwowhere pizzaoneis somewhere in the pizzatwo's name.

tableone有一列名为pizzaonetabletwo有一列名为pizzatwo。我想加入tableonetabletwo其中,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 需要“+”运算符的数字操作数。