oracle 如何在具有多个通配符的值的 sql plus 中使用 LIKE 语句?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4643409/
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
How to use LIKE statement in sql plus with multiple wild carded values?
提问by Sanjan Grero
my question is that currently if i want to query for multiple wildcarded values. I need to do something like this.
我的问题是,目前如果我想查询多个通配符值。我需要做这样的事情。
select customername from customers where customername like '%smith' or customername like '%potter' or customer name like '%harris' or customername like '%williams';
So I wanna ask from the experts, is there any easier way to do this?
所以想请教专家,有没有更简单的方法呢?
Regards, Sanjan
问候, 桑詹
回答by lll
Create a table of your 100 names
创建一个包含 100 个名字的表格
select customername from customers c inner join customersames cn on(c.customernamename like '%'+cn.searchForname)
select customername from customers c内加入customersames cn on(c.customernamename like '%'+cn.searchForname)
Can be a table variable if that helps.
如果有帮助,可以是表变量。
回答by Nylon Smile
you can use regular expressions
你可以使用正则表达式
EDIT: You can find plenty of resources online. take http://66.221.222.85/reference/regexp.htmlfor example.
编辑:您可以在网上找到大量资源。以http://66.221.222.85/reference/regexp.html为例。
Regular expressions are really powerful but can be very SLOW if applied carelessly. For your case they may not squeeze your syntax much because you need to type those names anyway and that's the bulky part.
正则表达式真的很强大,但如果不小心应用会很慢。对于您的情况,它们可能不会过多地压缩您的语法,因为您无论如何都需要键入这些名称,而这是庞大的部分。