How do I concatenate strings from a column into a single row?
Whats the logic to create the function in DB2.
Given is below.
Color
------
red
orange
blue
green
And return a resultset like this:
Colors
-------------------------
red,orange,blue,green 6 13497
On Nov 19, 2:28*pm, mark83anth...@gmail.com wrote:
How do I concatenate strings from a column into a single row?
Whats the logic to create the function in DB2.
Given is below.
Color
------
red
orange
blue
green
And return a resultset like this:
Colors
-------------------------
red,orange,blue,green
I will make it clear.
The table name is Colors
CREATE TABLE Colors
(
Color VARCHAR(32)
)
Values in the Table are
Color
------
red
orange
blue
green
My output should be when I do a Select * from Tabname, shd be
red,orange,blue,green
Waiting for your reply
Thanks in Advancd
On Nov 19, 12:49*pm, mark83anth...@gmail.com wrote:
On Nov 19, 2:28*pm, mark83anth...@gmail.com wrote:
How do I concatenate strings from a column into a single row?
Whats the logic to create the function in DB2.
Given is below.
Color
------
red
orange
blue
green
And return a resultset like this:
Colors
-------------------------
red,orange,blue,green
I will make it clear.
The table name is Colors
CREATE TABLE Colors
(
* * Color VARCHAR(32)
)
Values in the Table are
Color
------
red
orange
blue
green
My output should be when I do a Select * from Tabname, shd be
red,orange,blue,green
Waiting for your reply
Thanks in Advancd
Mark:
Have a look at a posting to this newsgroup titled "concatenating
historical records" from October '07. In it, I listed two ways I know
of/have learned to do this.
--Jeff
On Nov 19, 3:53*pm, jefftyzzer <jefftyz...@sbcglobal.netwrote:
On Nov 19, 12:49*pm, mark83anth...@gmail.com wrote:
On Nov 19, 2:28*pm, mark83anth...@gmail.com wrote:
How do I concatenate strings from a column into a single row?
Whats the logic to create the function in DB2.
Given is below.
Color
------
red
orange
blue
green
And return a resultset like this:
Colors
-------------------------
red,orange,blue,green
I will make it clear.
The table name is Colors
CREATE TABLE Colors
(
* * Color VARCHAR(32)
)
Values in the Table are
Color
------
red
orange
blue
green
My output should be when I do a Select * from Tabname, shd be
red,orange,blue,green
Waiting for your reply
Thanks in Advancd
Mark:
Have a look at a posting to this newsgroup titled "concatenating
historical records" from October '07. In it, I listed two ways I know
of/have learned to do this.
--Jeff- Hide quoted text -
- Show quoted text -
Hi,
I tried doing this
SELECT replace(replace(xml2clob(xmlagg(xmlelement(NAME a,
Color))),'<A>',''),'</A>',' ')
FROM Colors;
It works fine with my DB2 9.5 client on my machine but does not work
with Db2 Z OS 9.1.
It gives me the following error message
SQL0171N The data type, length or value of argument "1" of routine
"REPLACE"
is incorrect. SQLSTATE=42815
SQL0171N The data type, length or value of argument "1" of routine
"REPLACE" is incorrect.
Explanation:
The data type, length or value of argument "<n>" of routine "<name>"
is
incorrect.
The statement cannot be processed.
User response:
Ensure the arguments of the routine conform to the rules of the
routine.
sqlcode: -171
sqlstate: 42815
On Nov 19, 2:22*pm, mark83anth...@gmail.com wrote:
On Nov 19, 3:53*pm, jefftyzzer <jefftyz...@sbcglobal.netwrote:
On Nov 19, 12:49*pm, mark83anth...@gmail.com wrote:
On Nov 19, 2:28*pm, mark83anth...@gmail.com wrote:
How do I concatenate strings from a column into a single row?
Whats the logic to create the function in DB2.
Given is below.
Color
------
red
orange
blue
green
And return a resultset like this:
Colors
-------------------------
red,orange,blue,green
I will make it clear.
The table name is Colors
CREATE TABLE Colors
(
* * Color VARCHAR(32)
)
Values in the Table are
Color
------
red
orange
blue
green
My output should be when I do a Select * from Tabname, shd be
red,orange,blue,green
Waiting for your reply
Thanks in Advancd
Mark:
Have a look at a posting to this newsgroup titled "concatenating
historical records" from October '07. In it, I listed two ways I know
of/have learned to do this.
--Jeff- Hide quoted text -
- Show quoted text -
Hi,
I tried doing this
SELECT replace(replace(xml2clob(xmlagg(xmlelement(NAME a,
Color))),'<A>',''),'</A>',' ')
FROM Colors;
It works fine with my DB2 9.5 client on my machine but does not work
with Db2 Z OS 9.1.
It gives me the following error message
SQL0171N *The data type, length or value of argument "1" of routine
"REPLACE"
is incorrect. *SQLSTATE=42815
SQL0171N *The data type, length or value of argument "1" of routine
"REPLACE" is incorrect.
Explanation:
The data type, length or value of argument "<n>" of routine "<name>"
is
incorrect.
The statement cannot be processed.
User response:
Ensure the arguments of the routine conform to the rules of the
routine.
*sqlcode: -171
*sqlstate: 42815
Well, notwithstanding a simple fix for the problem you're having with
the XML function, assuming that DB2 9.1 for Z/OS supports recursive
common table expressions (CTEs), you could try the other technique
demonstrated in the earlier posting I mentioned.
--Jeff
DB2 for z/OS doesn't support casting XML data type to another data
type.
(See Table 13. Supported casts between built-in data types
on Page 80 of "DB2 Version 9.1 for z/OS SQL Reference".)
Also, DB2 for z/OS doesn't support XML2CLOB function.
I have a Table called Colors both in Db2 9.5 for LUW and DB2 9.1 on Z/OS
SELECT replace(replace(xmlagg(xmlelement(NAME a,NAME)),'<A>',' ' ),'</A>',' ') FROM TECPG01.TEST1111
It works fine with db2 on LUW but generates an error for Db2 on z/OS
saying that argument 1 of the routine REPLACE is wrong.
It was neccesary to add an XML2CLOB function on DB2 9.1 for LUW, like
this:
SELECT replace(replace(XML2CLOB(xmlagg(xmlelement(NAME a,
color))),'<A>', ''), '</A>', ' ') FROM Colors
I got error message SQL0440N for
SELECT replace(replace(xmlagg(xmlelement(NAME a, color)),'<A>', ''),
'</A>', ' ') FROM Colors
SQL0440N No authorized routine named "REPLACE" of type "FUNCTION"
having compatible arguments was found. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jay Chan |
last post by:
I am trying to export data from a SQLServer database into a text file
using a stored procedure. I want to be able to read it and debug it
easily; therefore, I want all the columns to indent nicely....
|
by: SWN |
last post by:
hi.
Trying to concatenate two columns:
select uname+' '+uaddress as NameAdr from tblUser
I only get the first field, name!!??
The datatype is both nvarchar. 100 and 50 chars long.
If I...
|
by: Lars Tackmann |
last post by:
Hi - I need a function to concatenate a variable number of strings.
I have two ideas but cannot deside which way to go.
1) use the "stdarg" macros - if i use these macros it will be easy
to step...
|
by: jt |
last post by:
I can't seem to find a way to concatenate strings that have nulls within the
string.
I have a string that I need another string that has nulls in it and what to
append
the 2nd string, 3 string...
|
by: Diego Martins |
last post by:
Since C++ (and STL) have many ways to do string concatenation, I want
to hear (read) from you how you do to concatenate strings with other
strings and other types. The approaches I know are:
--...
|
by: Dave-o |
last post by:
New learner.
For the print command and concatenation, the period is difficult for
my afflicted eyes to see, but the "+" seems to work. Is this an
accepted PHP convention?
Thank you,
David
|
by: Markus |
last post by:
Hi, guys.
I'm receiving a dynamic amount of strings and from these strings I need to make a single string containing them all. However, I need to preserve the NULL characters to separate the...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |