In one column i have a values like this.
Full Name
---------------
"Keith Warn"
"Hary Peter"
"Mag B Boston"
I want to break that column as 2 columns. like this..
First_column second column Third_column
----------------- ----------------- -----------------
Keith Warn
Hary Peter
Mag b Boston
For example if we take INITCAP command it will make first letter capitale to all words.
For example.
SELECT INITCAP('the soap') "Capitals" FROM DUAL;
Capitals
---------
The Soap
"INITCAP returns char, with the first letter of each word in uppercase, all other letters in lowercase. Words are delimited by white space or characters that are not alphanumeric. "
So oracle is recognizing the difference between words in a column by delimiting the spaces.
But i don't know why oracle is not provided any function for this.
Any body have other ideas on this. Any suggestion will help me. Thanks.
But, what you can do is select a substring out of the column, which is hokey because of where the break in the name occurs, OR use PL/SQL to select each row into a cursor, then compare each character in the name string to an array - once you hit a space, take what's been selected out into a concatenated name string and do an insert into a new, properly formed table. From there, take the remaining characters in the array, minus the space, concatenate those together, and do the second insert. Sounds like a pain in the butt? Yes. Should have created the table correctly in the first place, but all may not be lost. How was the data put in the table? One line at a time by hand? Or with a script? If with a script, modify it accordingly. If by hand, live and learn.
Okay, another way: select * from bad_table into a flat file - save it out to an external file that is tab delimited. Edit the file as necessary, then use SQL Loader to read in the flat file. How's that work for you?
As I can understand, you want to break the contents of your COL_X into three different columns COL_1 to COL_3 undeer the following rules:
COL_1: everything from first character up to the first blank character
COL_2: everything from the first blank to the second blank
COL_3: everything following the second blank
So here is somewhat messy code, but it should work:
I'm impressed with the effort jmodic put into this. However, since you claim it is not working for you, I suggest one of two courses of action:
1) Suck up to jmodic and ask him to further refine what he did.
2) Do the string array routine. That is guaranteed to work. Everytime you hit a space, an insert is made, and the rest of the array is processed. End of the array --> go to the next string in your cursor. Takes a lot more processing, but hey, what do you care? That's what computers are for.
Bookmarks