Solved

How to filter a SQL query on  a substring

Posted on 2014-09-29
3
495 Views
Last Modified: 2014-09-29
I currently have the following inelegant filter hard-coded into my query. Rather than hard-coding dates into the query, I'd like to filter based on a substring, i.e. if the last four characters are 09 or 10 or 11 or 12. How can I do this?

and COURSE_START_DATE in ('201209','201210','201211','201212','201309','201310','201311','201312','201409','201410','201411','201412')

Open in new window

0
Comment
Question by:mariita
  • 2
3 Comments
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40350162
>> if the last four characters are 09
Last four or last two?

Try this:
and regexp_like(COURSE_START_DATE,'(09|10|11|12)$')
0
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 40350167
or
and substr(COURSE_START_DATE,-2,2) in ('09','10','11','12')
0
 

Author Closing Comment

by:mariita
ID: 40350180
Last two. Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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…

863 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

21 Experts available now in Live!

Get 1:1 Help Now