Splitting up text into chunks (no split words)
622829May 14 2008 — edited May 14 2008I'm trying to figure out the best way to split up a body of text (say maybe 400-500 characters long) into 130 character-sized chunks with no words being split. I figured how to do this for the first chunk, but am having problems figuring out how to keep repeating it. Here's the code I have so far that calculates this properly for the first chunk:
declare
inc number := -1;
tmp_body nvarchar2(2000);
begin
tmp_body := 'blahblahblah...';
tmp_body := substr(tmp_body, 1, 130);
LOOP
if (substr(tmp_body, inc, 1) = ' ') then
exit;
end if;
inc := inc - 1;
END LOOP;
tmp_body := substr(tmp_body, 1, 130+inc);
end;
I know I need to substitute variables for the values of 1 and 130, right? Seems like this could get complicated very quickly unless I'm missing something.