Re: COLUMN WITH WORD_WRAP IN PL/SQL ????

From: george lewycky <gelewyc_at_nyct.com>
Date: 11 Dec 2003 09:30:55 -0800
Message-ID: <68aecc05.0312110930.68837694_at_posting.google.com>


Let me re-explain myself.

I have a description field totalling 220 bytes and I need to print the field from a table into a file using my PL/SQL program.

Currently my print code (below) is chopping the field up from 1st-70th bytes, and then 71st - 140th byte, but I found in SQL*Plus a built-in (see first post) text wrap feature and I trying to find an equivalent to use in PL/SQL !!! Because the splitting will truncate words, etc and doesnt look too professional.

Hope that makes it clearer

George Lewycky

       item_text  := substr(lines_record.item_description,1,70);
	if length(lines_record.item_description) > 70 then  
	    item_text2 := substr(lines_record.item_description,71,69);
		end if;

        DBMS_OUTPUT.put_line (' ' || item_text || '    ' || to_char 
           (lines_record.extended_amount,'99,999,999.99'));

         if length(lines_record.item_description) > 70 then
		     DBMS_OUTPUT.put_line (' ' || item_text2);






>
> Hello George,
>
> I'm not entirely sure what you mean by wrapping lines in PL/SQL,
> I assume you mean dbms_output or utl_file. So here's a procedural
> approach that uses dbms_output.
>
> The procedure uses substr to break the input string up into chunks
> of the required linesize, then instr to search backwards from the
> end for the first space character. It loops until the input string
> has been processed.
>
> SQL> create or replace procedure word_wrap (
> 2 p_str varchar2, p_linesize pls_integer, p_sep varchar2 := ' ')
> 3 as
> 4 l_str long := p_str || p_sep;
> 5 l_line long;
> 6 l_pos pls_integer;
> 7 begin
> 8 while l_str is not null loop
> 9 l_line := substr(l_str, 1, p_linesize);
> 10 l_pos := instr(l_line, p_sep, -1);
> 11 l_line := substr(l_line, 1, l_pos);
> 12 dbms_output.put_line(l_line);
> 13 l_str := substr(l_str, l_pos + 1);
> 14 end loop;
> 15 end;
> 16 /
>
> Procedure created.
>
> SQL>
> SQL> var s varchar2(1000)
> SQL> begin
> 2 :s := 'I am trying to take a field description for a column';
> 3 :s := :s || ' of about 200+ bytes and wrap the field into 3';
> 4 :s := :s || ' lines of 70 bytes apiece in PL/SQL';
> 5 end;
> 6 /
>
> PL/SQL procedure successfully completed.
>
> SQL> set serverout on
> SQL> exec word_wrap(:s, 70)
> I am trying to take a field description for a column of about 200+
> bytes and wrap the field into 3 lines of 70 bytes apiece in PL/SQL
>
> PL/SQL procedure successfully completed.
>
> SQL> exec word_wrap(:s, 50)
> I am trying to take a field description for a
> column of about 200+ bytes and wrap the field
> into 3 lines of 70 bytes apiece in PL/SQL
>
> PL/SQL procedure successfully completed.
>
> Hopefully if it's not what you want, there's something in there to
> give you some idea.
Received on Thu Dec 11 2003 - 18:30:55 CET

Original text of this message