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.

Go Back  dBforums > Database Server Software > Oracle > SQL Query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-07-08, 11:37
bmistry bmistry is offline
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.
Reply With Quote
  #2 (permalink)  
Old 01-07-08, 12:01
pablolee pablolee is offline
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.
Reply With Quote
  #3 (permalink)  
Old 01-07-08, 12:11
bmistry bmistry is offline
Registered User
 
Join Date: Jan 2006
Posts: 63
We have integrated a few of our systems and this is required.
Reply With Quote
  #4 (permalink)  
Old 01-07-08, 12:23
pablolee pablolee is offline
Registered User
 
Join Date: Dec 2007
Posts: 129
Then it is a simple
surname||', '||firstname
Reply With Quote
  #5 (permalink)  
Old 01-07-08, 12:25
bmistry bmistry is offline
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
Reply With Quote
  #6 (permalink)  
Old 01-07-08, 12:32
Littlefoot Littlefoot is offline
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>
Reply With Quote
  #7 (permalink)  
Old 01-07-08, 12:33
pablolee pablolee is offline
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)
Reply With Quote
  #8 (permalink)  
Old 01-07-08, 12:54
beilstwh beilstwh is offline
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!!
Reply With Quote
  #9 (permalink)  
Old 01-07-08, 12:58
bmistry bmistry is offline
Registered User
 
Join Date: Jan 2006
Posts: 63
I actually work for a Charity who are trying to find a cure for cancer!
Reply With Quote
  #10 (permalink)  
Old 01-07-08, 13:05
bmistry bmistry is offline
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.
Reply With Quote
  #11 (permalink)  
Old 01-08-08, 06:55
RBARAER RBARAER is offline
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 .
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

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