<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: How to solve the Text Formatting Problem in SQL</title>
	<atom:link href="http://oraqa.com/2008/01/08/how-to-solve-the-text-formatting-problem-in-sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://oraqa.com/2008/01/08/how-to-solve-the-text-formatting-problem-in-sql/</link>
	<description>Oracle Question and Answer</description>
	<lastBuildDate>Tue, 06 Jul 2010 14:28:12 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: newkid</title>
		<link>http://oraqa.com/2008/01/08/how-to-solve-the-text-formatting-problem-in-sql/comment-page-1/#comment-281</link>
		<dc:creator>newkid</dc:creator>
		<pubDate>Fri, 25 Jun 2010 15:48:36 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2008/01/08/how-to-solve-the-text-formatting-problem-in-sql/#comment-281</guid>
		<description>&lt;pre&gt;
VAR v_width NUMBER;
EXEC :v_width :=35;

WITH t3 AS (
select 1 as id,
&#039;Stop all the clocks, cut off the telephone, prevent the dog from barking with a juicy bone. The quick brown fox jumps over the lazy dog. Assiduously avoid any and all asinine alliterations.&#039;
as str from dual
)
,t2 AS (
SELECT id,rn, REGEXP_SUBSTR(str,&#039;[^ ]+&#039;,1,rn) str2
  FROM t3,(SELECT ROWNUM rn FROM (SELECT MAX(LENGTH(str)) m FROM t3) CONNECT BY ROWNUM&lt;=m)
)
,t1 AS (
SELECT id,rn,str2,MAX(rn) OVER(PARTITION BY id) len
  FROM t2
 WHERE str2 IS NOT NULL
)
,t (id,rn,str,cnt,len) AS (
SELECT id,1,str2,LENGTH(str2),len
 FROM t1
 WHERE rn=1
UNION ALL
SELECT t.id,t1.rn
      ,t.str&#124;&#124;(CASE WHEN cnt+LENGTH(t1.str2)+1&lt;=:v_width THEN &#039; &#039; ELSE CHR(10) END)&#124;&#124;t1.str2
      ,CASE WHEN cnt+LENGTH(t1.str2)+1&lt;=:v_width THEN cnt+LENGTH(t1.str2)+1
            ELSE LENGTH(t1.str2)
       END
      ,t.len
 FROM t,t1
WHERE t.id = t1.id
      AND t.rn=t1.rn-1
)
SELECT id,str FROM t WHERE rn=len
;

        ID
----------
STR
-------------------------------------------------
         1
Stop all the clocks, cut off the
telephone, prevent the dog from
barking with a juicy bone. The
quick brown fox jumps over the lazy
dog. Assiduously avoid any and all
asinine alliterations. 
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<pre>
VAR v_width NUMBER;
EXEC :v_width :=35;

WITH t3 AS (
select 1 as id,
'Stop all the clocks, cut off the telephone, prevent the dog from barking with a juicy bone. The quick brown fox jumps over the lazy dog. Assiduously avoid any and all asinine alliterations.'
as str from dual
)
,t2 AS (
SELECT id,rn, REGEXP_SUBSTR(str,'[^ ]+',1,rn) str2
  FROM t3,(SELECT ROWNUM rn FROM (SELECT MAX(LENGTH(str)) m FROM t3) CONNECT BY ROWNUM&lt;=m)
)
,t1 AS (
SELECT id,rn,str2,MAX(rn) OVER(PARTITION BY id) len
  FROM t2
 WHERE str2 IS NOT NULL
)
,t (id,rn,str,cnt,len) AS (
SELECT id,1,str2,LENGTH(str2),len
 FROM t1
 WHERE rn=1
UNION ALL
SELECT t.id,t1.rn
      ,t.str||(CASE WHEN cnt+LENGTH(t1.str2)+1&lt;=:v_width THEN ' ' ELSE CHR(10) END)||t1.str2
      ,CASE WHEN cnt+LENGTH(t1.str2)+1&lt;=:v_width THEN cnt+LENGTH(t1.str2)+1
            ELSE LENGTH(t1.str2)
       END
      ,t.len
 FROM t,t1
WHERE t.id = t1.id
      AND t.rn=t1.rn-1
)
SELECT id,str FROM t WHERE rn=len
;

        ID
----------
STR
-------------------------------------------------
         1
Stop all the clocks, cut off the
telephone, prevent the dog from
barking with a juicy bone. The
quick brown fox jumps over the lazy
dog. Assiduously avoid any and all
asinine alliterations.
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>
