Solved

Oracle 9i - Select part of a variable length string

Posted on 2014-10-16
3
338 Views
Last Modified: 2014-11-11
Experts,
I am trying to select a value from the middle of a variable length string.  I think SUBSTR with INSTR will work but am having trouble with the syntax

in this example string:
'10058698.325 Fatal error reported: No Item <GMAFH - 60-90161> was found. File name /u02/......'

I want to return everything after 'reported:' and before 'File' so I return:
No Item <GMAFH - 60-90161> was found

I have figured out how to use INSTR to select the up to or after the words, but can figure out how two combine both.
0
Comment
Question by:JDCam
  • 2
3 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 40385446
SELECT SUBSTR(your_column, b, e - b)
  FROM (SELECT your_column, INSTR(your_column, 'reported:') + 9 b, INSTR(your_column, 'File') e
          FROM your_table)
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 40385464
or directly...

SELECT SUBSTR(
           your_column,
           INSTR(your_column, 'reported:') + 9,
           INSTR(your_column, 'File') - (INSTR(your_column, 'reported:') + 9)
       )
  FROM your_table;

and, if the space after "reported: " shouldn't be included in the output, adjust the offsets


SELECT SUBSTR(
           your_column,
           INSTR(your_column, 'reported: ') + 10,
           INSTR(your_column, 'File') - (INSTR(your_column, 'reported: ') + 10)
       )
  FROM your_table;
0
 

Author Closing Comment

by:JDCam
ID: 40435881
thanks... working great
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
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…
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

749 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