Originally posted by: Shuxclams
I have a column I want to convert to firstname_lastname
Jones, John shoudl be John_Jones
What do I want to use.
Shux
Originally posted by: kamper
Oh. I totally read your post the other way around
If the data in your current column is very uniform (always "Fname, Lname" with no funky characters) then the suggestions above will be fine. If it gets any trickier I would move the string splitting into application space where you have more powerful string manipulation. Just do a select on all the names and loop through and do updates.
Off topic, there's another reason why postgres is cooler than mysql: half decent regex support so you could easily do this using sql.
Uh oh. I might have just been caught talking out of my assOriginally posted by: Armitage
:roll: What's wrong with the regex support in mysql?Originally posted by: kamper
Oh. I totally read your post the other way around
If the data in your current column is very uniform (always "Fname, Lname" with no funky characters) then the suggestions above will be fine. If it gets any trickier I would move the string splitting into application space where you have more powerful string manipulation. Just do a select on all the names and loop through and do updates.
Off topic, there's another reason why postgres is cooler than mysql: half decent regex support so you could easily do this using sql.
expr REGEXP pat
expr RLIKE pat
Performs a pattern match of a string expression expr against a pattern pat. The pattern can be an extended regular expression. See section G MySQL Regular Expressions. Returns 1 if expr matches pat, otherwise returns 0. RLIKE is a synonym for REGEXP, provided for mSQL compatibility. Note: Because MySQL uses the C escape syntax in strings (for example, `\n'), you must double any `\' that you use in your REGEXP strings. As of MySQL Version 3.23.4, REGEXP is case-insensitive for normal (not binary) strings:
mysql> SELECT 'Monty!' REGEXP 'm%y%%';
-> 0
mysql> SELECT 'Monty!' REGEXP '.*';
-> 1
mysql> SELECT 'new*\n*line' REGEXP 'new\\*.\\*line';
-> 1
mysql> SELECT "a" REGEXP "A", "a" REGEXP BINARY "A";
-> 1 0
mysql> SELECT "a" REGEXP "^[a-d]";
-> 1
Originally posted by: Jeraden
assuming its always in the lastname, first name and the column is col1
set col1 = ltrim(substr(col1,instr(col1,',')+1)) || '_' || substr(col1,1,instr(col1,',')-1)
thats oracle syntax, so use the appropriate mysql equivalents for those functions.
Originally posted by: Shuxclams
Originally posted by: Jeraden
assuming its always in the lastname, first name and the column is col1
set col1 = ltrim(substr(col1,instr(col1,',')+1)) || '_' || substr(col1,1,instr(col1,',')-1)
thats oracle syntax, so use the appropriate mysql equivalents for those functions.
See attached code for the equiv.
The only thing I don't understand about your script is the OR ( || ), is that different in Oracle?
SHUX
1193 - Unknown system variable 'lastnamefirst'
SHUX