[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

oracle query - how to combine like and in clause

Posted on 2011-09-23
6
Medium Priority
?
928 Views
Last Modified: 2012-05-12
I have to write a sql statement similar to in clause but I dont know the exact value of type so I want to do like clause but can I have more than 1 matching string?

for example type value is flash MB, stream MB, traffic MB

I want to write select * from stats where type like (%Fl%MB,%str%MB,Traf%MB)
0
Comment
Question by:mahjag
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 36588474
you can't

do it as a multiple  or clauses

where type like '%Fl%MB'
or type like '%str%MB'
or type like 'Traf%MB'
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 36588491
or use regular expressions but you still must list each


where regexp_like(type,'(Fl|str|Traf).*MB')
0
 
LVL 15

Expert Comment

by:Devinder Singh Virdi
ID: 36588630
I believe you can also use XML to write dynamic where clause.
I am not good in XML, Stuber can help in that.
Something like :-

select
XMLTABLE( DBMS_XMLGEN.getxml('select * from TEMP_TABLE where &cond') )
from dual
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 74

Expert Comment

by:sdstuber
ID: 36588691
sure, it would be possible, but that would be REALLY inefficient as you'd be constructing the same set of OR clauses or regexp clauses,  or worse... multiple queries, one for each condtion
then turning those results into xml, then you'll have to parse the xml to get your columns back.

so, yes, I "could" write that, but I won't because it's definitely not the right way to go
0
 

Author Comment

by:mahjag
ID: 36589073
regexp_like(type,'(Fl|str|Traf).*MB')
will this capture before and after like %fl% - ?
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 36589115
it should,

easiest way to check is to try it
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question