468,140 Members | 1,650 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,140 developers. It's quick & easy.

COLUMN WITH WORD_WRAP IN PL/SQL ????

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!!!!!!

I know this can be done in SQL*Plus as show below but how can I take
this command and have it work in PL/SQL ??? Any ideas, samples ?????

Thanks in advance

George Lewycky
ge*****@nyct.com
================================================== ============
COLUMN remark FORMAT A20 WORD_WRAP
the selected column remark is given a width of 20 characters. The
contents of the field is printed 20 characters to the line with the
break ending after a full word on each line. This will mean some
records actual print on more than one line.
Word-wrap in PL/SQL ???
Can COLUMN with WORD_WRAP from SQL*Plus be used in PL/SQL ??

Also note that in the first command you must enter the expression
exactly as you entered it (or will enter it) in the SELECT command.
Otherwise, SQL*Plus cannot match the COLUMN command to the appropriate
column.
To wrap long values in a column named REMARKS, you can enter
SQL> COLUMN REMARKS FORMAT A20 WRAP
For example:
CUSTOMER DATE QUANTITY REMARKS
---------- --------- -------- --------------------
123 25-AUG-86 144 This order must be s
hipped by air freigh
t to ORD

If you replace WRAP with WORD_WRAP, REMARKS looks like this:
CUSTOMER DATE QUANTITY REMARKS
---------- --------- -------- ---------------------
123 25-AUG-86 144 This order must be
shipped by air freight
to ORD

If you specify TRUNCATE, REMARKS looks like this:
CUSTOMER DATE QUANTITY REMARKS
---------- --------- -------- --------------------
123 25-AUG-86 144 This order must be s
Jul 19 '05 #1
5 15203
VC
Hello,

You can insert a 'new line' character (Windows would require a 'cr', in
addition):

create table t1 as select rpad('test', 210, '*') x from dual;
select substr(x, 1,70)||chr(10)||substr(x, 71, 70)||chr(10)||substr(x,
141,70) from t1;

Rgds.
"george lewycky" <ge*****@nyct.com> wrote in message
news:68**************************@posting.google.c om...
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!!!!!!

I know this can be done in SQL*Plus as show below but how can I take
this command and have it work in PL/SQL ??? Any ideas, samples ?????

Thanks in advance

George Lewycky
ge*****@nyct.com
================================================== ============
COLUMN remark FORMAT A20 WORD_WRAP
the selected column remark is given a width of 20 characters. The
contents of the field is printed 20 characters to the line with the
break ending after a full word on each line. This will mean some
records actual print on more than one line.
Word-wrap in PL/SQL ???
Can COLUMN with WORD_WRAP from SQL*Plus be used in PL/SQL ??

Also note that in the first command you must enter the expression
exactly as you entered it (or will enter it) in the SELECT command.
Otherwise, SQL*Plus cannot match the COLUMN command to the appropriate
column.
To wrap long values in a column named REMARKS, you can enter
SQL> COLUMN REMARKS FORMAT A20 WRAP
For example:
CUSTOMER DATE QUANTITY REMARKS
---------- --------- -------- --------------------
123 25-AUG-86 144 This order must be s
hipped by air freigh
t to ORD

If you replace WRAP with WORD_WRAP, REMARKS looks like this:
CUSTOMER DATE QUANTITY REMARKS
---------- --------- -------- ---------------------
123 25-AUG-86 144 This order must be
shipped by air freight
to ORD

If you specify TRUNCATE, REMARKS looks like this:
CUSTOMER DATE QUANTITY REMARKS
---------- --------- -------- --------------------
123 25-AUG-86 144 This order must be s

Jul 19 '05 #2
ge*****@nyct.com (george lewycky) wrote in message news:<68**************************@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_','p***@e u.o')
address from dual ---> pobox 002 is full of spam and not read;
Jul 19 '05 #3
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.

Jul 19 '05 #4
ge*****@nyct.com (george lewycky) wrote in message news:<68**************************@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.

SQLcreate 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>
SQLvar s varchar2(1000)
SQLbegin
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.

SQLset serverout on
SQLexec 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.

SQLexec 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_','p***@e u.o')
address from dual ---pobox 002 is full of spam and not read;
Jun 27 '08 #5
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.

SQLcreate 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>
SQLvar s varchar2(1000)
SQLbegin
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.

SQLset serverout on
SQLexec 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.

SQLexec 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.
Jun 27 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by perspolis | last post: by
6 posts views Thread by Robert Schuldenfrei | last post: by
19 posts views Thread by Owen T. Soroke | last post: by
3 posts views Thread by TPhelps | last post: by
27 posts views Thread by didacticone | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.