80 character string
546215Nov 16 2006 — edited Nov 17 2006hi,
i have to develop a PL/SQL function which would take input a string for ex
i/p:i am a gdgdgdasgdyasgdasygdysgdysgdysgdysagdsgdygsaydgysgdyagdysaydgsdyasgdysagfdufgudgfudgfudgufgududf boy of
since the fourth word (or any word) in the line is greater than 80 characters it should split it and the include space :
o/p:
i am a gdgdgdasgdyasgdasygdysgdysgdysgdysagdsgdygsaydgy sgdyagdysaydgsdyasgdysagfdufgudgfudgfudgufgududf boy of
please try to give a solution to this
the function i am using is like this
create or replace function count_length_words(string varchar2)
return varchar2 is
w_string varchar2(10000) := string;
w_output varchar2(10000);
wordlength integer;
s_string varchar2(10000);
a_string varchar2(10000);
begin
while instr(w_string, ' ') > 0 loop
w_output := w_output || ' ' ||
substr(w_string, 1, instr(w_string, ' ') - 1) || '-' ||
length(substr(w_string, 1, instr(w_string, ' ') - 1));
wordlength := length(substr(w_string, 1, instr(w_string, ' ') - 1));
s_string := substr(w_string, 1, instr(w_string, ' ') - 1);
if wordlength >= 80 then
select substr(string, 1, length) || ' ' || substr(string, length + 1)
into a_string
from (select s_string string, length(s_string) / 2 length from dual);
end if;
w_string := substr(w_string, instr(w_string, ' ') + 1);
end loop;
w_output := w_output || ' ' || substr(w_string, 1) || '-' ||
length(substr(w_string, 1));
return trim(a_string); -- it is returning the broken 80 character string not the entir string
end;