0

我有一个搜索功能,我可以在我的数据库中找到地址行 1,但我想知道是否可以找到地址行 1、2、3、4、5,它们都是同一行上的不同属性,具体取决于用户搜索。请参阅下面的代码。任何帮助将不胜感激,谢谢。

这有效:

<sql:query var ="NameCheck" scope = "session" dataSource = "${bookdB}">

    SELECT * FROM Company   
    WHERE Address_1 LIKE ?

    <sql:param value = "%${param.category}%" />

</sql:query>


这是否可能以某种形式的语法(“||”、“OR”运算符)。

SELECT * FROM Company
WHERE Address_1 OR Address_2 OR Address_3 OR Address_4 OR Address_5 LIKE ?
4

2 回答 2

1

In Sql, yes you can use OR instead of ||, however this is the only way to select the rows in conditions, but you must complete each and every condition and then start a new condition like this:

SELECT * FROM Company
WHERE Address_1 LIKE 
OR Address_2 LIKE %a OR 
Address_3 LIKE %a OR 
Address_4 LIKE%a OR 
Address_5 LIKE %a

Computer won't change its algorithm, so you should stick to its language :)

To search multiple addresses you can use AND and then write them in the HTML. You can use OR when one condition is not true, then move to the next one. This way, you must close the condition before OR operator.

http://www.w3schools.com/sql/sql_and_or.asp

于 2013-10-16T12:41:59.023 回答
1

您使用的语法不正确。

您必须执行以下操作:

SELECT * FROM Company
WHERE Address_1 LIKE ...
   OR Address_2 LIKE ...
   OR Address_3 LIKE ...
   OR Address_4 LIKE ...
   OR Address_5 LIKE ...
于 2013-10-16T12:38:17.433 回答