Home » SQL & PL/SQL » SQL & PL/SQL » writing text on new lines
writing text on new lines [message #248753] Sun, 01 July 2007 11:05 Go to next message
Messages: 13
Registered: June 2007
Junior Member
I have a wraptext procedure which accepts input text and fits it within given output length .
Following is my test script

Accept line Prompt 'enter text : '
Accept len prompt 'enter length of output text '

loc_text VARCHAR2 (2000) := &line ;
text_out varchar2(1000);

loc_line_length INTEGER := &len;
loc_lines INTEGER;

/* Display a header containing the text and ruler. */
DBMS_OUTPUT.PUT_LINE ('====================');
DBMS_OUTPUT.put_LINE (RPAD('1',length(loc_text),'2345678901'));
('Wrapping to: '||TO_CHAR(loc_line_length)||' characters.');

wrapt(loc_text, loc_line_length, text_out, loc_lines);
ENtertext ' This is a very long line of text which we will wrap to smaller
length : 10
For which I get output showing how text should be divided
This is a very long line of text which we will wrap to smaller 12345678901234567890123456789012345678901234567890 Wrapping to: 10 characters.

What should I write in test script to get the following desired output (text broken (without breaking words apart)with given output length on new lines...
This is a
very long
line of
text which
Re: writing text on new lines [message #248756 is a reply to message #248753] Sun, 01 July 2007 11:37 Go to previous message
Michel Cadot
Messages: 64418
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
The algorithm is, assuming you want you break at N characters, go to the Nth character, if it is a space (or a tab, or a new line...) then output this N characters.
Otherwise go backward till you find a space (or...) and then output till this character.
And continue with the next N characters till the end.

Previous Topic: Murging with excel
Next Topic: Raising exceptions
Goto Forum:

Current Time: Mon Feb 20 00:13:34 CST 2017

Total time taken to generate the page: 0.16814 seconds