If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > string function - concat

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-10-06, 20:52
bobjohnson360 bobjohnson360 is offline
Registered User
 
Join Date: Jan 2006
Posts: 15
string function - concat

I have used concat many times in Oracle and just switched
over to DB2 personal.

Does this version support concat and if so how would I
concat a character field from 1000 to a1000.
ex:
update inventory set part = concat( 'a', part);

inventory - table.
part - field with 1000 value.

any ideas/ thanks
BJ
Reply With Quote
  #2 (permalink)  
Old 01-11-06, 04:10
juliane26 juliane26 is offline
Registered User
 
Join Date: Oct 2005
Posts: 109
why not using the standard operator:

update inventory set part = 'a' || part;

works both on Oracle and DB2 and is SQL standard
__________________
Juliane
Reply With Quote
  #3 (permalink)  
Old 01-11-06, 04:19
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
DB2 also supports the CONCAT scalar function; "||" is actually a shortcut to that function.
You have to make sure, though, that both arguments of concat (or of "||") are of datatype "text"; if "part" is numeric, use
Code:
update inventory set part = concat( 'a', digits(part));
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
  #4 (permalink)  
Old 01-13-06, 16:35
bobjohnson360 bobjohnson360 is offline
Registered User
 
Join Date: Jan 2006
Posts: 15
concat data error

All works well but when I try to insert a letter on the right hand side of the field' part' value it seems the blank spaces
create a problem.I increased the spaces from 10 to 15
but it still gave the same error message.

Do I have to rtrim blank spaces just before I conact when
inserting on right side , if so how?
error message:
SQL0433N Value "1000 a" is too long. SQLSTATE=22001






Thanks again
Bob
Reply With Quote
  #5 (permalink)  
Old 01-13-06, 17:08
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Quote:
Originally Posted by bobjohnson360
... it seems the blank spaces create a problem.
Do I have to rtrim blank spaces just before I concat
That's right. Thus:
Code:
rtrim(a) || ' and the rest'
will remove trailing spaces from a before concatenating.
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
  #6 (permalink)  
Old 01-14-06, 19:12
bobjohnson360 bobjohnson360 is offline
Registered User
 
Join Date: Jan 2006
Posts: 15
concat data too long error

Peter


Works just great !

Thanks
BJ
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

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