Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Oracle 9i - Select part of a variable length string

Posted on 2014-10-16
3
Medium Priority
?
363 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 2000 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

927 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