Solved

Substr Query Question in oracle sql

Posted on 2011-03-04
3
326 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 73

Accepted Solution

by:
sdstuber earned 500 total points
Comment Utility
if using 10g try...


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

Expert Comment

by:sdstuber
Comment Utility
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
Comment Utility
Thank you for the quick response
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

728 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

12 Experts available now in Live!

Get 1:1 Help Now