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: 19244
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts To get the count of rows for every 1 ... DB2 3
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
Search our Forums:

Back to Top