Solved

Oracle Query Problem

Posted on 2006-07-24
5
992 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
[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
5 Comments
 
LVL 143

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Use of Exception to end a Loop 3 54
Email query results in HTML 6 38
How to create an alias for a column name in ORACLE sql ? 2 48
Oracle perfomance issue. 4 18
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
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