| |
Welcome to the dBforums forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact contact support.
If you prefer not to see double-underlined words and corresponding ads, place your cursor here for ContentLink opt out.
|
 |

01-07-08, 11:37
|
|
Registered User
|
|
Join Date: Jan 2006
Posts: 63
|
|
|
SQL Query
|
Afternoon
I need a little help with some sql. I have a table within my oracle db with the following columns
Name
Firstname
surname
The name column is not being populated to read the surname and then the Firstname ie it's reading Paul Smith instead of Smith Paul. I need an update sql that will populate the Name Column so the surname is in first followed by a , then the firstname.
A point in the right direction would be great.
Thanks in advance.
|
|

01-07-08, 12:01
|
|
Registered User
|
|
Join Date: Dec 2007
Posts: 129
|
|
I would question the wisdom of storing the name column at all. I would be inclined to suggest calculating this value when needed.
|
|

01-07-08, 12:11
|
|
Registered User
|
|
Join Date: Jan 2006
Posts: 63
|
|
|
We have integrated a few of our systems and this is required.
|
|

01-07-08, 12:23
|
|
Registered User
|
|
Join Date: Dec 2007
Posts: 129
|
|
Then it is a simple
surname||', '||firstname
|
|

01-07-08, 12:25
|
|
Registered User
|
|
Join Date: Jan 2006
Posts: 63
|
|
sorry to be a pain but could you send me the full query my sql is not great.
Thanks
|
|

01-07-08, 12:32
|
|
Lost Boy
|
|
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 2,717
|
|
Check this example and, if necessary, change it to suit your needs.
Code:
SQL> WITH TEST AS
2 (SELECT 'Paul Smith' name FROM dual
3 UNION
4 SELECT 'Little Foot' FROM dual
5 )
6 SELECT SUBSTR(name, 1, INSTR(name, ' ')) first_name,
7 SUBSTR(name, INSTR(name, ' ') + 1, LENGTH(name)) surname
8 FROM TEST;
FIRST_NAME SURNAME
----------- -----------
Little Foot
Paul Smith
SQL>
|
|

01-07-08, 12:33
|
|
Registered User
|
|
Join Date: Dec 2007
Posts: 129
|
|
Sorry but no. Have a look at here
It will give you the syntax that you require.
Obviously that was a reply to the OP, not you littlefoot  (although I think you may have misunderstood the OP's question)
|
|

01-07-08, 12:54
|
|
Registered User
|
|
Join Date: Jun 2004
Location: Liverpool, NY USA
Posts: 1,642
|
|
I am not trying to be mean, but if you are not capable of writting such a simple update statement and you do not have anyone else that you can ask at your place of employment, could you tell us what your company is so that I can drop any stock that I might have in it! That being said,
update my_table
set name = surname||', '||firstname;
__________________
Bill
Cream always raises to the top, and so does the scum!!
|
|

01-07-08, 12:58
|
|
Registered User
|
|
Join Date: Jan 2006
Posts: 63
|
|
I actually work for a Charity who are trying to find a cure for cancer!
|
|

01-07-08, 13:05
|
|
Registered User
|
|
Join Date: Jan 2006
Posts: 63
|
|
What I also meant to say is that you def wouldnt have bought shares so you got nothing to worry about.
|
|

01-08-08, 06:55
|
|
Registered User
|
|
Join Date: Aug 2004
Location: France
Posts: 754
|
|
Quote:
|
Originally Posted by pablolee
I would question the wisdom of storing the name column at all. I would be inclined to suggest calculating this value when needed.
|
I agree.
Quote:
|
Originally Posted by bmistry
We have integrated a few of our systems and this is required.
|
I would recommend to use a view :
Code:
CREATE OR REPLACE VIEW V_MY_TABLE(
Name,
FirstName,
SurName
)
AS
SELECT SurName||', '||FirstName,
FirstName,
SurName
FROM My_Table;
Doing so, any insert/update on my_table will only affect firstname and surname (no need to calculate NAME) and the view will always provide the three.
HTH & Regards,
rbaraer
__________________
ORA-000TK : No bind variable detected... Shared Pool Alert code 5 - Nuclear query ready  .
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|