The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-03-2006
dsravan dsravan is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 190
Sorry question on SQL

Experts,

I need small help in oracle. I am just putting this question here because i think there are SQL geniuses here as well as UNIX.

I have a string that contains the First name, Middle name and last name in one field in the table in Oracle. I need to extract each one of them seperately. Can any one help with sql for this please.

Field in the table
Quote:
e.g Jody E Mcquire
Required Output:
Quote:
Jody
E
Mcquire
I will appreciate help in this matter.

Thanks
  #2 (permalink)  
Old 10-03-2006
mona's Avatar
mona mona is offline
Registered User
  
 

Join Date: Nov 2005
Location: Singapore
Posts: 96
Hi,

You can post the SQL or Oracle related questions in Oracle forum.

The below query should help you.


Code:
SELECT trim(DECODE(ROWNUM,1,SUBSTR(STR,1,INSTR(STR,' ',1)),
                                    LENGTH(STR)-LENGTH(REPLACE(STR,' '))+1,SUBSTR(STR,INSTR(STR,' ',-1,1)),
                                     SUBSTR(STR,INSTR(STR,' ',1,ROWNUM-1), INSTR(STR,' ',1,ROWNUM)-INSTR(STR,' ',1,ROWNUM-1))
                               ))  STR1
                 FROM (SELECT 'Jody E Mcquire' STR FROM DUAL),ALL_TABLES
                 WHERE ROWNUM <= LENGTH(STR)-LENGTH(REPLACE(STR,' '))+1
                  ORDER BY ROWNUM

  #3 (permalink)  
Old 10-03-2006
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
Try something like....
Code:
SQL> SELECT substr('Jody E Mcquire',1,instr('Jody E Mcquire',' ')-1) first FROM dual;

FIRST
-----
Jody

SQL> SELECT substr('Jody E Mcquire',instr('Jody E Mcquire',' ',1,2)+1) last FROM dual;

LAST
-------
Mcquire

  #4 (permalink)  
Old 10-03-2006
dsravan dsravan is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 190
Ygor/Mona,

Thank you guys for the replys. But how can i get the Middle initial also. Please help.

Thanks,
  #5 (permalink)  
Old 10-03-2006
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
You can write your own SQL for the middle initial using the instr and substr functions. Use the above examples for guidance.
  #6 (permalink)  
Old 10-10-2007
senthil_is senthil_is is offline
Registered User
  
 

Join Date: Sep 2007
Location: singapore
Posts: 35
String Check in String

Hi,
i need to check my string1 is in another string2.


input_filename=017200910.DC30025
if [ my file has .DC3 ]
then
i need do some action


Can anyone tell me how to check my string is in another string.

example
i need to check .DC3 is in 017200910.DC30025
Closed Thread

Bookmarks

Tags
awk, awk trim, trim, trim awk

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:15 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0