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

From: Martin Burbridge <pobox002_at_bebub.com>
Date: 9 Dec 2003 19:32:37 -0800
Message-ID: <45a06b65.0312091932.7080b636_at_posting.google.com>


gelewyc_at_nyct.com (george lewycky) wrote in message news:<68aecc05.0312091137.5ba8ae4e_at_posting.google.com>...
> 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!!!!!!
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.

-- 
Martin Burbridge
select translate('1o2o40536b7b8b9c_m','12456789_','pbx0_at_eu.o')
address from dual ---> pobox 002 is full of spam and not read;
Received on Wed Dec 10 2003 - 04:32:37 CET

Original text of this message