Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2003
    Posts
    20

    Unanswered: wrap text on output

    Is there anyway in PL/SQL that I can force output to wrap to the next line? I'm working on a report that shows questionnaire questions and some of them are pretty long. My current setup truncates the question if it goes past 60 characters, anymore than that it the formatting of the report is messed up. What I'd like it to do is when 60 characters are reached, it should wrap to the next line like Word and even report builder does. Is this possible?

    I have the following procedure to format the output:

    PROCEDURE put ( string IN CHAR, pad IN CHAR := 'N'
    , pad_num IN NUMBER := 0 ) IS
    cen_pad number ;
    string2 varchar2(255) ;
    BEGIN
    string2 := nvl(string,' ') ;
    if pad in ('C','c') then
    cen_pad := floor(( pad_num - length(string2) ) / 2) ;
    for i in 1 .. cen_pad loop
    string2 := ' '||string2 ;
    end loop ;
    string2 := rpad(string2,pad_num,' ') ;
    elsif pad in ('R','r') then
    string2 := rpad(string2,pad_num,' ') ;
    elsif pad in ('L','l') then
    string2 := lpad(string2,pad_num,' ') ;
    elsif pad = 'N' then
    null ;
    end if ;
    dbms_output.put(string2) ;
    END ;


    As well as this one to print a new line:

    PROCEDURE putl(string2 in char) IS
    BEGIN
    dbms_output.put_line(string2);
    END;

    Is there some way I could modify these to make this happen or is there some other way to do it?

    thanks,
    Ian

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    If you are using SQL Plus then this should suffice:

    Code:
    SET LINESIZE 80
    SET SERVEROUT ON SIZE 1000000 FORMAT WORD_WRAPPED
    SQL> begin
      2    dbms_output.put_line(rpad('blah ',200,'blah '));
      3  end;
      4  /
    blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
    blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
    blah blah blah blah blah blah blah blah
    
    PL/SQL procedure successfully completed.
    Last edited by andrewst; 06-09-04 at 09:20.

  3. #3
    Join Date
    Jun 2003
    Posts
    20
    Unfortunately that doesn't work. I'm printing out a variable for a start so it would be like

    dbms_output.put_line(rpad(v_text,200,v_text));

    so if when it prints the value of v_text is less than 200 it prints it again. Then it throws a new line and prints the next value. so it would be like.

    1.were you happy with the service?were you happy with the

    2 do you wish to raise a complaint about the service that yo

    what i'd like is:

    1.were you happy with the service?

    2 do you wish to raise a complaint about the service that
    you recently received?

    thanks for your help so far

  4. #4
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    Sorry if my post wasn't clear. The rpad part wasn't the solution, it was just there to manufacture a long string of text to demo the WORD_WRAPPED option! See this:

    Code:
      1  declare
      2    v_text varchar2(255);
      3  begin
      4    v_text := 'Is there anyway in PL/SQL that I can force output '
      5      || 'to wrap to the next line? '
      6      || 'I''m working on a report that shows questionnaire questions and some of them'
      7      || ' are pretty long. ';
      8    dbms_output.put_line (v_text);
      9* end;
    SQL> /
    Is there anyway in PL/SQL that I can force output to wrap
    to the next line? I'm working on a report that shows
    questionnaire questions and some of them are pretty long.
    
    PL/SQL procedure successfully completed.

  5. #5
    Join Date
    Jul 2004
    Location
    Dar es Salaam, Tanzania
    Posts
    1

    Wrapping text in pl/sql output

    Yes Pals,

    If you are working out of sql*Plus you may use the following sequence:

    || CHR(13) || CHR(10)

    for insserting the line breaks. I personally had this problem when I wanted to break a line of text in emails but this sequence helped me cleat out the problem. Let me know if this is what you wanted.

    Stephen
    Last edited by mtenga; 07-05-04 at 07:05. Reason: A spleeing correction

  6. #6
    Join Date
    May 2004
    Location
    Dominican Republic
    Posts
    721
    If you are working with a report and showing these values into a Field, why not set the Horizontal Elasticity of the Field to the desired wide and set this property to Fixed, and then set the Vertial Elasticity property to Variable ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •