Hai everybody...!
I have a problem here .. Hope I can get help by answers..
I have a table A
ID DATA
1 aa;bb
2 aa;bb;cc
3 aa;cc
4 bb;cc
I wish to get a table B like
ID A B C
1 aa bb null
2 aa bb cc
3 aa null cc
4 null bb cc
I would like get table B a result by using DB2 UDF,,
wish have details of create function & how to call it ..
I am new to DB2.. waiting for Help..!
Thanks in advance...
12 2154
Thanks for your response..
I have tried that one earlier.. it throws [Error] - &;WHERE ordinal. SQLCODE=-7, SQLSTATE=42601, DRIVER=3.53.71
I am using DB2 Aqua Data Studio 8.0.8
so waiting for further clarification..
It would be very helpful ..
Thanks once again in advance..
What code did you execute when you go that error?
Here is the code I used... - 1)CREATE or REPLACE FUNCTION elemIdx (string CLOB(64K) )
-
2)RETURNS TABLE ( ordinal INTEGER, index INTEGER )
-
3)LANGUAGE SQL
-
4)DETERMINISTIC
-
5)NO EXTERNAL ACTION
-
6)CONTAINS SQL
-
7)RETURN WITH t(ordinal, index) AS
-
8) ( VALUES ( 0, 0 )
-
9) UNION ALL
-
10) SELECT ordinal+1, COALESCE(NULLIF(LOCATE(';',
-
11) string,index+1),0),LENGTH(string)+1) FROM t
-
12) WHERE ordinal < 10000 AND LOCATE(';', string,
-
13) index+1) <> 0 )
-
14) SELECT ordinal, index FROM t
-
15) UNION ALL
-
16) SELECT MAX(ordinal)+1, LENGTH(string)+1 FROM t
In the above code I am not clear about the following...
[ CLOB(64K) ]
[ <10000 AND ]
[ <> ]
Thanks in advance..
Don't just copy and paste code without looking at what you are executing. That is quite a dangerous thing to do.
1.) Don't execute it with those line numbers
2.) Read the tutorial to understand what the SQL is doing.
Thanks..
I do executed without line numbers ..
just for understanding i added line number manually for posting reply...
as i mentioned early
[ CLOB(64K) ]
[ <10000 AND ]
[ <> ]
are not mentioned clearly in tutorial...
Thanks again..
Most likely some of the characters are supposed to be less than (<) instead of < and their code formatter didn't display them right so replace < with < and > with >
yes you are right...! http://www.ibm.com/developerworks/da...03stolze1.html
helps to get the seperate Stings from a group of String as input ...
i.e.s from 'aa;bb;cc' as input gives 'aa' 'bb' 'cc' in three records as output...
but still i am not getting how to get ...
table B
ID A B C
1 aa bb null
2 aa bb cc
3 aa null cc
4 null bb cc
as output from the input
table A
ID DATA
1 aa;bb
2 aa;bb;cc
3 aa;cc
4 bb;cc
i.e., how to pass each DATA in all records of table A as String (by looping) as input
& how to insert the result into the fields A B C of table B respectively..
Thanks Again in Advance...
insert from a select (or from a group of selects)
Thanks.. but still not getting how to insert with group of select...
I have the following...
[code - function returns a table] - CREATE or REPLACE FUNCTION elemIdx ( string VARCHAR(225) )
-
RETURNS TABLE ( ordinal INTEGER, index INTEGER )
-
LANGUAGE SQL
-
DETERMINISTIC
-
NO EXTERNAL ACTION
-
CONTAINS SQL
-
RETURN
-
WITH t(ordinal, index) AS
-
( VALUES ( 0, 0 )
-
UNION ALL
-
SELECT ordinal+1, COALESCE(NULLIF(LOCATE(';', string, index+1), 0),LENGTH(string)+1) FROM t
-
WHERE ordinal<1000 AND LOCATE(';', string, index+1) <> 0 )
-
SELECT ordinal, index FROM t
-
UNION ALL
-
SELECT MAX(ordinal)+1, LENGTH(string)+1 FROM t
-
-
[code - query ] -
SELECT *
-
FROM TABLE (elemIdx('abc; def; ghi; 123') ) AS t ORDER BY 1
-
[result of above query - a table] -
ordinal index
-
0 0
-
1 4
-
2 9
-
3 14
-
4 19
[result]
[code-function returns a table] -
CREATE OR REPLACE FUNCTION elements ( string VARCHAR(225) )
-
RETURNS TABLE ( elements VARCHAR(225) )
-
LANGUAGE SQL
-
DETERMINISTIC
-
NO EXTERNAL ACTION
-
CONTAINS SQL
-
RETURN
-
WITH t(ordinal, index) AS
-
( SELECT ordinal, index FROM TABLE ( elemIdx(string) ) AS x )
-
SELECT SUBSTR(string, t1.index+1, t2.index - t1.index - 1)
-
FROM t AS t1 JOIN t AS t2 ON ( t2.ordinal = t1.ordinal+1 )
-
-
[code- query that returns a table again] -
SELECT VARCHAR(elem, 100)
-
FROM TABLE ( elements('abc; def; ghi; 123') ) AS t(elem)
-
-
[result of above query - a table]
[result]
i donot have any clear idea about
how to proceed further....
Help me how to proceed ... Thanks in Advance...
insert into your new table values(colA, colB)
values
(select from the table with the concatenated values and split the values and get the first split record, select from the table with the concatenated values and split the values and get the second split record)
Thanks...
I am not getting any progress...
as I am getting close to deadline,could you help me with queries using above functions..
source table is
Table_name as source
ID DATA
1 aa;bb
2 aa;bb;cc
3 aa;cc
4 bb;cc
and destination table is
Table_name as destination (ID is auto generated)
ID A B C
- - - -
expected result is
Table_name: destination
ID A B C
1 aa bb null
2 aa bb cc
3 aa null cc
4 null bb cc
Thanks in Advance..
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: sans_spam |
last post by:
I'm writing a classic ASP application that records all logging of user
logins on our support site. The logging is a rolling window of how many
people have logged in for a given month, i.e. tracked...
|
by: Joe Bloggs |
last post by:
Hello,
I have a form linking two tables but they have one field that is
shared called "device" I want to allow data input into one of the
fields and hide the other (so I need it automatically...
|
by: SheldonMopes |
last post by:
I'm not sure how to go about this:
I have a form bound to tableA. I would like to be able to use the
AfterUpdate event of textbox1 to write the contents (after some
manipulation) to TableB. How...
|
by: jaYPee |
last post by:
as of now i am using a stored procedure from my sql server 2000 to
insert record from another table. what i need now is on how can i
insert record by not using the stored procedure and insert it...
|
by: Prabu Subroto |
last post by:
Dear my friends...
I created a table (named : sven1). I want to populate
this table with the record from another table (named :
appoinment).
but I don't know how to formulate the sql query.
...
| |
by: travismorien |
last post by:
I have four tables of different "entities". One table contains
information for "people", one for "trusts", one for "companies" and one
for "self managed super funds". Each type of entity has an...
|
by: Deano |
last post by:
Problem is that there are lots and lots of fields in an employee record. I
specify a form control as the criterion for one of those fields which is the
value of the primary key for that record. ...
|
by: MLH |
last post by:
DELETE tblPreliminaryVINs.* FROM tblPreliminaryVINs INNER JOIN
tblVehicleJobs ON tblPreliminaryVINs.PVIN = tblVehicleJobs.SerialNum;
The above SQL does not work for me. I get an error
I cannot...
|
by: webcat |
last post by:
Hi
I need to UPDATE data into a table
mainData
which contains many fields - one is CODE and one is DESCRIPTION
another table DESCRIP is a lookup - it also contains the same fields, but...
|
by: lee weaver |
last post by:
I have a table for employees and a table that shows which containers they have access to and a table of all containers.
What i need to do is when adding a new employee i need to add a record to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |