?
Solved

Substr Query Question in oracle sql

Posted on 2011-03-04
3
Medium Priority
?
377 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 2000 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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

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…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

777 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