var sql = 'select TEXTID,TEXTTYPE,TEXTPAR1,TEXTPAR2,LENGTH(TEXT) as TEXTLEN';
var segsize = 1000;
var maxlen = 10000;
var segnum = 1;
for (var i=1;i<=maxlen;i+=segsize) {
sql += ', SUBSTR(TEXT,'+i+','+segsize+') as TEXTSEG'+segnum;
segnum++;
}
sql += ' from CCTEXTS'
sql