Sorry question on SQL


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sorry question on SQL
# 1  
Old 10-03-2006
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  
Old 10-03-2006
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  
Old 10-03-2006
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  
Old 10-03-2006
Ygor/Mona,

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

Thanks,
# 5  
Old 10-03-2006
You can write your own SQL for the middle initial using the instr and substr functions. Use the above examples for guidance.
# 6  
Old 10-10-2007
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Storing multiple sql queries output into variable by running sql command only once

Hi All, I want to run multiple sql queries and store the data in variable but i want to use sql command only once. Is there a way without running sql command twice and storing.Please advise. Eg : Select 'Query 1 output' from dual; Select 'Query 2 output' from dual; I want to... (3 Replies)
Discussion started by: Rokkesh
3 Replies

2. Shell Programming and Scripting

Shell Scripting question with SQL

hey i have to connect to sql through shell script , then store the value of the query in a variable and then compare it after some time after running a process. i have used this code but it is not working. #!/bin/sh Val = (sqlplus -s rte/rted2@rel76d2 <<! SELECT MAX(STAT_ID) FROM CVT_STATS;... (3 Replies)
Discussion started by: ramsavi
3 Replies

3. UNIX for Advanced & Expert Users

Call parallel sql scripts from shell and return status when both sql are done

Hi Experts: I have a shell script that's kicked off by cron. Inside this shell script, I need to kick off two or more oracle sql scripts to process different groups of tables. And when both sql scripts are done, I will continue in the shell script to do other things like checking processing... (3 Replies)
Discussion started by: huasheng8
3 Replies

4. Shell Programming and Scripting

Execute multiple SQL scripts from single SQL Plus connection

Hi! I would like to do a single connection to sqlplus and execute some querys. Actually I do for every query one connection to database i.e echo 'select STATUS from v$instance; exit' > $SQL_FILE sqlplus user/pass@sid @$SQL_FILE > $SELECT_RESULT echo 'select VERSION from v$instance;... (6 Replies)
Discussion started by: guif
6 Replies

5. Shell Programming and Scripting

How to use sql data file in unix csv file as input to an sql query from shell

Hi , I used the below script to get the sql data into csv file using unix scripting. I m getting the output into an output file but the output file is not displayed in a separe columns . #!/bin/ksh export FILE_PATH=/maav/home/xyz/abc/ rm $FILE_PATH/sample.csv sqlplus -s... (2 Replies)
Discussion started by: Nareshp
2 Replies

6. UNIX for Dummies Questions & Answers

Execute PL/SQL function from Unix script (.sql file)

Hi guys, I am new on here, I have a function in oracle that returns a specific value: create or replace PACKAGE BODY "CTC_ASDGET_SCHED" AS FUNCTION FN_ASDSCHEDULE_GET RETURN VARCHAR2 AS BEGIN DECLARE ASDSchedule varchar2(6); ASDComplete... (1 Reply)
Discussion started by: reptile
1 Replies

7. Programming

Simple SQL question!

Hi all, I would like to display more values of different tables in one row. The issue is that I want to display more values from the same column! exp. Table1 id | col1 ---------- 1 val1 2 val2 Table2 id | col2 ----------- 1 val2 2 val3 3 val4 (2 Replies)
Discussion started by: research3
2 Replies

8. Shell Programming and Scripting

unix variables from sql / pl/sql

How do I dynamically assign the below output to unix shell variables so I can build a menu in a shell script? Example: var1 = 1 var2= SYSTEM var3 = 2 var4= UNDOTBS1 and so on, then in the shell script I can use the variables to build a menu. set serveroutput on declare... (2 Replies)
Discussion started by: djehres
2 Replies

9. Shell Programming and Scripting

sql command question

Hi, Table1 ====== Code1 Field1 Table2 ====== Code1 Field1 Would anyone be able to help me know what's the best sql command to delete the entry in Table1 if its Code1-Field1 combination is already existing in Table2. I used this one - delete from Table1 where Code1 in (select... (1 Reply)
Discussion started by: gholdbhurg
1 Replies

10. Shell Programming and Scripting

Calling SQL LDR and SQL plus scripts in a shell script

Hi- I am trying to achieve the following in a script so I can schedule it on a cron job. I am fairly new to the unix environment... I have written a shell script that reads a flat file and loads the data into an Oracle table (Table1) via SQLLDR. This Works fine. Then, I run a nested insert... (5 Replies)
Discussion started by: rajagavini
5 Replies
Login or Register to Ask a Question