niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Databases » Oracle » Server
instr question
Post new topic   Reply to topic Page 1 of 1 [5 Posts] View previous topic :: View next topic
Author Message
kimberly.shaffer@gmail.co
*nix forums beginner


Joined: 25 Sep 2005
Posts: 14

PostPosted: Thu Jul 20, 2006 6:28 pm    Post subject: instr question Reply with 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
Back to top
Brian Peasland
*nix forums Guru


Joined: 04 Apr 2006
Posts: 301

PostPosted: Thu Jul 20, 2006 6:35 pm    Post subject: Re: instr question Reply with quote

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

PostPosted: Thu Jul 20, 2006 6:55 pm    Post subject: Re: instr question Reply with 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?


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

PostPosted: Thu Jul 20, 2006 7:15 pm    Post subject: Re: instr question Reply with quote

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

PostPosted: Thu Jul 20, 2006 7:52 pm    Post subject: Re: instr question Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [5 Posts] View previous topic :: View next topic
The time now is Mon Dec 01, 2008 7:17 pm | All times are GMT
navigation Forum index » Databases » Oracle » Server
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Newbie question: How to forward a domain to a mailbox? leei Postfix 0 Fri Aug 24, 2007 4:55 pm
No new posts configuration question for httpd Karl Wang Apache 1 Fri Jul 21, 2006 2:10 pm
No new posts nim problem/question Ron AIX 0 Fri Jul 21, 2006 1:57 pm
No new posts question for JAVA developer who r using postgres sql as b... deepak pal PostgreSQL 1 Fri Jul 21, 2006 9:00 am
No new posts Encryption Question dtuttle1@gmail.com Berkeley DB 2 Thu Jul 20, 2006 10:09 pm

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
[ Time: 0.2446s ][ Queries: 16 (0.1549s) ][ GZIP on - Debug on ]