|
|
|
|
|
|
| Author |
Message |
kimberly.shaffer@gmail.co *nix forums beginner
Joined: 25 Sep 2005
Posts: 14
|
Posted: Thu Jul 20, 2006 6:28 pm Post subject:
instr question
|
|
|
I am using oracle 9.2 and am a newbie trying to figure out the instr
argument, and just can't wrap my brain around it. Or maybe I'm going
about this the wrong way with the wrong function. Say I have a simple
statement:
select currentfield from current table;
and it brings me back something like
-m first_string next_string one_more_string last_string
-m second_string next_string one_more_string last_string
-m third_string next_string one_more_string last_string
and I just want it to look like (in my return)
first_string
second_string
third_string
and strip out all the remaining strings and the -m prefix
is that possible? Can someone example me with this so I can see where
I am going wrong?
thx in advance and apologies if this is really simple.
ks |
|
| Back to top |
|
 |
Brian Peasland *nix forums Guru
Joined: 04 Apr 2006
Posts: 301
|
Posted: Thu Jul 20, 2006 6:35 pm Post subject:
Re: instr question
|
|
|
kimberly.shaffer@gmail.com wrote:
| Quote: | I am using oracle 9.2 and am a newbie trying to figure out the instr
argument, and just can't wrap my brain around it. Or maybe I'm going
about this the wrong way with the wrong function. Say I have a simple
statement:
select currentfield from current table;
and it brings me back something like
-m first_string next_string one_more_string last_string
-m second_string next_string one_more_string last_string
-m third_string next_string one_more_string last_string
and I just want it to look like (in my return)
first_string
second_string
third_string
and strip out all the remaining strings and the -m prefix
is that possible? Can someone example me with this so I can see where
I am going wrong?
thx in advance and apologies if this is really simple.
ks
|
So if I get what you are trying to do, you want to remove all but the
characters between the first and second space. The INSTR function can be
used to find the space.
INSTR(currentfield,' ') returns the position of the first space.
INSTR(currentfield,' ',1,2) returns the position of the second space
(starting at the 1st character in the column).
Now that you have that, use the SUBSTR function to return the characters
between those spaces:
SELECT SUBSTR(currentfield,INSTR(currentfield),' ')+1,
INSTR(currentfield,' ',1,2) - NSTR(currentfield),' ')-1)
FROM current_table;
HTH,
Brian
--
===================================================================
Brian Peasland
dba@nospam.peasland.net
http://www.peasland.net
Remove the "nospam." from the email address to email me.
"I can give it to you cheap, quick, and good.
Now pick two out of the three" - Unknown |
|
| Back to top |
|
 |
kimberly.shaffer@gmail.co *nix forums beginner
Joined: 25 Sep 2005
Posts: 14
|
Posted: Thu Jul 20, 2006 6:55 pm Post subject:
Re: instr question
|
|
|
Thank you Brian,
When I sort of plug in my current field and current table just to see
what results I get, I get the following error
SELECT SUBSTR(so_act_arg,INSTR(so_act_arg),' ')+1,
INSTR(so_act_arg,' ',1,2) - NSTR(so_act_arg),' ')-1)
FROM appworx.so_object_cond
WHERE so_act_arg LIKE '-m%';
FROM keyword not found where expected. What am I doing wrong?
Brian Peasland wrote:
| Quote: | kimberly.shaffer@gmail.com wrote:
I am using oracle 9.2 and am a newbie trying to figure out the instr
argument, and just can't wrap my brain around it. Or maybe I'm going
about this the wrong way with the wrong function. Say I have a simple
statement:
select currentfield from current table;
and it brings me back something like
-m first_string next_string one_more_string last_string
-m second_string next_string one_more_string last_string
-m third_string next_string one_more_string last_string
and I just want it to look like (in my return)
first_string
second_string
third_string
and strip out all the remaining strings and the -m prefix
is that possible? Can someone example me with this so I can see where
I am going wrong?
thx in advance and apologies if this is really simple.
ks
So if I get what you are trying to do, you want to remove all but the
characters between the first and second space. The INSTR function can be
used to find the space.
INSTR(currentfield,' ') returns the position of the first space.
INSTR(currentfield,' ',1,2) returns the position of the second space
(starting at the 1st character in the column).
Now that you have that, use the SUBSTR function to return the characters
between those spaces:
SELECT SUBSTR(currentfield,INSTR(currentfield),' ')+1,
INSTR(currentfield,' ',1,2) - NSTR(currentfield),' ')-1)
FROM current_table;
HTH,
Brian
--
===================================================================
Brian Peasland
dba@nospam.peasland.net
http://www.peasland.net
Remove the "nospam." from the email address to email me.
"I can give it to you cheap, quick, and good.
Now pick two out of the three" - Unknown |
|
|
| Back to top |
|
 |
chris.hulan@gmail.com *nix forums beginner
Joined: 10 May 2006
Posts: 13
|
Posted: Thu Jul 20, 2006 7:15 pm Post subject:
Re: instr question
|
|
|
kimberly.shaffer@gmail.com wrote:
| Quote: | Thank you Brian,
When I sort of plug in my current field and current table just to see
what results I get, I get the following error
SELECT SUBSTR(so_act_arg,INSTR(so_act_arg),' ')+1,
INSTR(so_act_arg,' ',1,2) - NSTR(so_act_arg),' ')-1)
FROM appworx.so_object_cond
WHERE so_act_arg LIKE '-m%';
FROM keyword not found where expected. What am I doing wrong?
|
a tool that does SQL auto-formating (like TOAD) is usefull for this
type of stuff.
Try:
SELECT SUBSTR (so_act_arg
, INSTR (so_act_arg, ' ') + 1
, INSTR (so_act_arg, ' ', 1, 2) - INSTR (so_act_arg, ' ')
- 1
)
FROM appworx.so_object_cond
WHERE so_act_arg LIKE '-m%'; |
|
| Back to top |
|
 |
kimberly.shaffer@gmail.co *nix forums beginner
Joined: 25 Sep 2005
Posts: 14
|
Posted: Thu Jul 20, 2006 7:52 pm Post subject:
Re: instr question
|
|
|
That worked great, thanks - I was using sqldeveloper, and my artisan is
tied up in another report, so I didn't know it was so picky with the
formatting. I'm new! But thank you. This was a very simple example
that I can sit down and wrap my brain around and I totally appreciate
you writing me back.
Try and keep cool!
me
chris.hulan@gmail.com wrote:
| Quote: | kimberly.shaffer@gmail.com wrote:
Thank you Brian,
When I sort of plug in my current field and current table just to see
what results I get, I get the following error
SELECT SUBSTR(so_act_arg,INSTR(so_act_arg),' ')+1,
INSTR(so_act_arg,' ',1,2) - NSTR(so_act_arg),' ')-1)
FROM appworx.so_object_cond
WHERE so_act_arg LIKE '-m%';
FROM keyword not found where expected. What am I doing wrong?
a tool that does SQL auto-formating (like TOAD) is usefull for this
type of stuff.
Try:
SELECT SUBSTR (so_act_arg
, INSTR (so_act_arg, ' ') + 1
, INSTR (so_act_arg, ' ', 1, 2) - INSTR (so_act_arg, ' ')
- 1
)
FROM appworx.so_object_cond
WHERE so_act_arg LIKE '-m%'; |
|
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Mon Dec 01, 2008 7:17 pm | All times are GMT
|
|
Loans | Loans | Mortgage | Credit Cards | Credit Card
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|