Solved

Substr Query Question in oracle sql

Posted on 2011-03-04
3
357 Views
Last Modified: 2012-06-27
I have the following select statement with substring

SUBSTR (NVL (historical_separate.work_done, active_separate.work_done),1,INSTR (NVL(historical_separate.work_done, active_separate.work_done),',',1,1)- 1)AS "Repair Code"

say I have data in the field of M21,17,5

The above statement gives me M21

but if I have data of only M21

it gives me blank

I need to have it show M21 not blank.  How do I accomplish this?
0
Comment
Question by:JDay2
  • 2
3 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 35037785
if using 10g try...


regexp_substr(NVL (historical_separate.work_done, active_separate.work_done),'[^,]+')
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 35037808
if you are using an older version that doesn't support  regular expressions try


CASE
           WHEN INSTR(NVL(historical_separate.work_done, active_separate.work_done), ',') > 0
           THEN
               SUBSTR(
                   NVL(historical_separate.work_done, active_separate.work_done),
                   1,
                   INSTR(NVL(historical_separate.work_done, active_separate.work_done), ',', 1, 1)
                   - 1)
           ELSE
               NVL(historical_separate.work_done, active_separate.work_done)
       END
0
 

Author Closing Comment

by:JDay2
ID: 35037847
Thank you for the quick response
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

679 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