IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to split a column of VARCHAR(4000) into multiple rows.


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
swatheeswaran

New User


Joined: 04 Nov 2008
Posts: 7
Location: Chennai

PostPosted: Sun Feb 21, 2010 2:58 pm
Reply with quote

How to split a column of VARCHAR(4000) into multiple rows of length 80 each using SQL query.

For example. a column has ABCDEFGHIJ,for length 2, o/p should be
AB
CD
EF
GH
IJ
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Mon Feb 22, 2010 12:03 am
Reply with quote

Hello,

Suggest you write a tiny bit of program code to read the varchar, split the data, and either write a sequential file to LOAD or directly INSERT the new rows. If the volume is high, the inserts will probably not perform acceptably. . .
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Mon Feb 22, 2010 2:48 pm
Reply with quote

It's do-able, maybe not desirable :
Code:
with cnt(stpos) as (
select 1 from sysibm.sysdummy1
union all
select stpos + 80 from cnt where stpos < 3920)

select substr(vchar_column,stpos, min(80,length(vchar_column) - stpos + 1)) from Table1 , cnt
where stpos  <= length(vchar-column)
and table1.pk = ?
Back to top
View user's profile Send private message
View previous topic : : View next topic  
Post new topic   Reply to topic All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Format data from multiple records usi... SYNCSORT 4
No new posts To Sort detail records in a file with... SYNCSORT 5
No new posts To Populate Trailer cnt in the file w... SYNCSORT 1
No new posts Converting VARCHAR to XML DB2 1
No new posts Multiple INSPECTS on a big size file COBOL Programming 6
Search our Forums:


Back to Top