有没有“LIKE"的组合?和“IN"在 SQL 中?

Is there a combination of quot;LIKEquot; and quot;INquot; in SQL?(有没有“LIKE的组合?和“IN在 SQL 中?)
本文介绍了有没有“LIKE"的组合?和“IN"在 SQL 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 SQL 中,我(遗憾地)经常不得不使用LIKE"条件,因为数据库几乎违反了所有规范化规则.我现在无法改变这一点.但这与问题无关.

In SQL I (sadly) often have to use "LIKE" conditions due to databases that violate nearly every rule of normalization. I can't change that right now. But that's irrelevant to the question.

此外,我经常使用诸如 WHERE something in (1,1,2,3,5,8,13,21) 之类的条件来提高我的 SQL 语句的可读性和灵活性.

Further, I often use conditions like WHERE something in (1,1,2,3,5,8,13,21) for better readability and flexibility of my SQL statements.

有没有什么办法可以在不编写复杂的子选择的情况下将这两件事结合起来?

Is there any possible way to combine these two things without writing complicated sub-selects?

我想要像 WHERE something LIKE ('bla%', '%foo%', 'batz%') 一样简单的东西,而不是这样:

I want something as easy as WHERE something LIKE ('bla%', '%foo%', 'batz%') instead of this:

WHERE something LIKE 'bla%'
OR something LIKE '%foo%'
OR something LIKE 'batz%'

我在这里使用 SQl Server 和 Oracle,但我很感兴趣,如果这在任何 RDBMS 中都可行.

I'm working with SQl Server and Oracle here but I'm interested if this is possible in any RDBMS at all.

推荐答案

LIKE & 没有组合SQL 中的 IN,更不用说 TSQL (SQL Server) 或 PLSQL (Oracle).部分原因是全文搜索 (FTS) 是推荐的替代方案.

There is no combination of LIKE & IN in SQL, much less in TSQL (SQL Server) or PLSQL (Oracle). Part of the reason for that is because Full Text Search (FTS) is the recommended alternative.

Oracle 和 SQL Server FTS 实现都支持 CONTAINS 关键字,但语法仍然略有不同:

Both Oracle and SQL Server FTS implementations support the CONTAINS keyword, but the syntax is still slightly different:

WHERE CONTAINS(t.something, 'bla OR foo OR batz', 1) > 0

SQL 服务器:

WHERE CONTAINS(t.something, '"bla*" OR "foo*" OR "batz*"')

您查询的列必须是全文索引.

The column you are querying must be full-text indexed.

参考:

  • 使用 Oracle Text 构建全文搜索应用程序
  • 了解 SQL Server Full-文本

这篇关于有没有“LIKE"的组合?和“IN"在 SQL 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)