sql - How to combine IN operator with LIKE condition (or best way to get comparable results) -


I have to select the rows where a field starts with one of several different prefixes:

 Select  from the table * where fields such as 'ab%' or fields like 'cd%' or "ef%" ... ...  

using SQL What's the best way to do Oracle or SQL Server? I'm looking for something like the following statement (which is wrong):

  Select * from the table where in the field ('ab%', 'cd%', 'ef%',). ..)  

or

  select from the table where in the field (choose foo from the bar)  

edited Do: I want to see how it is done with giving all the prefixes in one helpful statement and giving it to all prefixes.

The length of the prefixes is not fixed.

By joining your prefix table with your actual table, both SQL Server & amp; Oracle Announcement @ Table tab (Field VARCHAR (32)) DECLARE @ Prefix Tables (prefix VARCHAR (32)) Insert into the eligible values ​​('ABC') INSERT @Table Enter VALUES ('def') Enabled values ​​('ADEF') @ Valid values ​​('DEFAB'). Insert @free values ​​('EFABD') @Prinfix values ​​('AB%') INSERT INSERT Choose from prefix value ('de%'). PF like @Profix PF on T. Field from @TableTInner Prefix


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -