Solved

oracle query - how to combine like and in clause

Posted on 2011-09-23
6
845 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
  • 4
6 Comments
 
LVL 73

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 73

Accepted Solution

by:
sdstuber earned 125 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 73

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 73

Expert Comment

by:sdstuber
ID: 36589115
it should,

easiest way to check is to try it
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Via a live example, show how to take different types of Oracle backups using RMAN.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now