Solved

Oracle: Function help to trim value

Posted on 2013-11-15
5
476 Views
Last Modified: 2013-11-18
Experts,

I have a field called "Request_ID", that contains two merged Request ID's in the form of "000000001098990|000000029558106".  I would like to only show all values before the "|".  So show only "000000001098990".  Is there a way to do this?

this works but, is this the best way because what if the amount of values increase?
SUBSTR ((AU.request_id),0,(LENGTH(AU.request_id)-16)) AS REQUEST_ID_MOD,

Current ouput:          
TKT-1412155      000000001098990|000000029558106
TKT-1412155      000000001098970|000000029558106
TKT-1412155      000000001098991|000000029558106
TKT-1412155      000000001098957|000000029558106

Needing ouput:
TKT-1412155      000000001098990
TKT-1412155      000000001098970
TKT-1412155      000000001098991
TKT-1412155      000000001098957

Thanks
0
Comment
Question by:Maliki Hassani
5 Comments
 
LVL 22

Accepted Solution

by:
Steve Wales earned 500 total points
ID: 39651305
The INSTR function returns the first occurrence of a character in a string.

So, you could do something like:

select substr(col1,1,instr(col1,'|')-1)

This will take a substring of your output string, up to the character before the position of the '|'.

(Assuming that the | character that separates them is always going to be the first occurrence).
0
 

Author Closing Comment

by:Maliki Hassani
ID: 39651317
Thank you!
0
 
LVL 13

Expert Comment

by:duncanb7
ID: 39651324
SELECT SUBSTRING_INDEX(Request_ID, '|', 1)
it will get the value  000000001098990


////////////////////-------SELECT SUBSTRING_INDEX(Request_ID, '|', 2)
///////////////////--------it will get the value  000000029558106

Hope it works for you
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39657881
duncanb7,

Oracle doesn't have a SUBSTRING_INDEX function.
0
 

Author Comment

by:Maliki Hassani
ID: 39657908
Thanks!
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Union 2 queries to a cte (temp table perhaps) 9 41
T-SQL Default value in Select? 5 38
format dd/mm/yyyy parameter 16 30
Current Month Filter in Visual Studio 10 22
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…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
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
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

861 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