Solved

Oracle 9i - Select part of a variable length string

Posted on 2014-10-16
3
349 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
[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

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
 
LVL 1

Author Closing Comment

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

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and theā€¦
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Via a live example, show how to take different types of Oracle backups using RMAN.
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.
Suggested Courses

615 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