Solved

Oracle Query Problem

Posted on 2006-07-24
5
993 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

Technology Partners: 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

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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

717 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