Solved

Oracle Query Problem

Posted on 2006-07-24
5
989 Views
Last Modified: 2008-03-17
Here is my query:

SELECT R.COMPONENT, substr(R.COMPONENT,1,instr(R.COMPONENT,' ')-1)
FROM CPI.NAI_RESULTS R

It is looking a row and seeing if R.COMPONENT has a space in it, then it will get all the information before the first space.

That is correct.

My issue:

I want to return the word if there is no space at all.  Here is some examples:

R.COMPONENT
-----------------
one two three    <--       should return one (this would work currently)
one two            <--       should return one (this would work currently)
one                  <--       should return one (this doesn't work right now.  It returns nothing.)

Thanks
0
Comment
Question by:daugh016
5 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17167606
SELECT R.COMPONENT, CASE WHEN instr(R.COMPONENT,' ') = 0 THEN r.COMPONENT ELSE substr(R.COMPONENT,1,instr(R.COMPONENT,' ')-1) END as Component
FROM CPI.NAI_RESULTS R
0
 
LVL 27

Expert Comment

by:sujith80
ID: 17167931

SELECT R.COMPONENT, substr(R.COMPONENT,1, decode(instr(R.COMPONENT,' '), 0, length(R.COMPONENT), instr(R.COMPONENT,' ')-1))
FROM CPI.NAI_RESULTS R
0
 

Author Comment

by:daugh016
ID: 17167939
It said "didn't expect 'instr' after the SELECT column list
0
 
LVL 14

Accepted Solution

by:
sathyagiri earned 125 total points
ID: 17168126
SELECT R.COMPONENT, decode(instr(R.COMPONENT,' '),0,R.COMPONENT,substr(R.COMPONENT,1,instr(R.COMPONENT,' ')-1))
FROM CPI.NAI_RESULTS R
0
 

Author Comment

by:daugh016
ID: 17168168
That was it. Thanks sathyagiri
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
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.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now