?
Solved

oracle query - how to combine like and in clause

Posted on 2011-09-23
6
Medium Priority
?
944 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 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 Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
Suggested Courses
Course of the Month13 days, 18 hours left to enroll

809 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