<?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 find the longest common substring patterns starting from the string head/tail</title>
	<atom:link href="http://oraqa.com/2007/03/13/how-to-find-the-longest-common-substring-patterns-starting-from-the-string-headtail/feed/" rel="self" type="application/rss+xml" />
	<link>http://oraqa.com/2007/03/13/how-to-find-the-longest-common-substring-patterns-starting-from-the-string-headtail/</link>
	<description>Oracle Question and Answer</description>
	<lastBuildDate>Mon, 19 Dec 2011 14:21:07 -0700</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/2007/03/13/how-to-find-the-longest-common-substring-patterns-starting-from-the-string-headtail/comment-page-1/#comment-285</link>
		<dc:creator>newkid</dc:creator>
		<pubDate>Fri, 25 Jun 2010 20:19:27 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2007/03/13/how-to-find-the-longest-common-substring-patterns-starting-from-the-string-headtail/#comment-285</guid>
		<description>&lt;pre&gt;
WITH t AS (
SELECT t5.*,MIN(LENGTH(in_str)) OVER(PARTITION BY grp_id) len FROM t5
)
SELECT DISTINCT id,grp_id,in_str
      ,MAX(CASE WHEN head_cnt=1 THEN head END) OVER(PARTITION BY grp_id)
      ,SUBSTR(MAX(CASE WHEN tail_cnt=1 THEN LPAD(rn,10)&#124;&#124;tail END) OVER(PARTITION BY grp_id),11)
FROM (SELECT t2.*,COUNT(DISTINCT head) OVER(PARTITION BY grp_id,rn) head_cnt,COUNT(DISTINCT tail) OVER(PARTITION BY grp_id,rn) tail_cnt
        FROM (
      SELECT t.*,rn,SUBSTR(in_str,1,rn) head,SUBSTR(in_str,-rn) tail
        FROM t,(SELECT ROWNUM rn FROM (SELECT MAX(len) m FROM t) CONNECT BY ROWNUM&lt;=m)
       WHERE rn&lt;=t.len
             ) t2
      )
WHERE head_cnt=1 OR tail_cnt=1;
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<pre>
WITH t AS (
SELECT t5.*,MIN(LENGTH(in_str)) OVER(PARTITION BY grp_id) len FROM t5
)
SELECT DISTINCT id,grp_id,in_str
      ,MAX(CASE WHEN head_cnt=1 THEN head END) OVER(PARTITION BY grp_id)
      ,SUBSTR(MAX(CASE WHEN tail_cnt=1 THEN LPAD(rn,10)||tail END) OVER(PARTITION BY grp_id),11)
FROM (SELECT t2.*,COUNT(DISTINCT head) OVER(PARTITION BY grp_id,rn) head_cnt,COUNT(DISTINCT tail) OVER(PARTITION BY grp_id,rn) tail_cnt
        FROM (
      SELECT t.*,rn,SUBSTR(in_str,1,rn) head,SUBSTR(in_str,-rn) tail
        FROM t,(SELECT ROWNUM rn FROM (SELECT MAX(len) m FROM t) CONNECT BY ROWNUM&lt;=m)
       WHERE rn&lt;=t.len
             ) t2
      )
WHERE head_cnt=1 OR tail_cnt=1;
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Maxim Demenko</title>
		<link>http://oraqa.com/2007/03/13/how-to-find-the-longest-common-substring-patterns-starting-from-the-string-headtail/comment-page-1/#comment-208</link>
		<dc:creator>Maxim Demenko</dc:creator>
		<pubDate>Thu, 05 Apr 2007 20:08:09 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2007/03/13/how-to-find-the-longest-common-substring-patterns-starting-from-the-string-headtail/#comment-208</guid>
		<description>Well, here is another alternative (maybe not so elegant, but with supported packaged REVERSE function ) - using the table from previous example.

&lt;pre&gt;
WITH t as
        (SELECT id, 
                grp_id, 
                in_str, 
                min(in_str) over (partition by grp_id) ref_str, 
                utl_raw.cast_to_raw(in_str) raw_str, 
                utl_raw.cast_to_raw(min(in_str) over (partition by grp_id)) ref_raw_str, 
                utl_raw.reverse(utl_raw.cast_to_raw(in_str)) reverse_raw_str, 
                utl_raw.reverse(utl_raw.cast_to_raw(min(in_str) over (partition by grp_id))) reverse_ref_raw_str 
        FROM    t5
        )
        , 
        t1 as 
        (SELECT id,
                grp_id,
                in_str,
                ref_raw_str,
                reverse_ref_raw_str, 
                min(nullif(utl_raw.compare(ref_raw_str,raw_str),0)) over(partition by grp_id)                  -1 head_len, 
                min(nullif(utl_raw.compare(reverse_ref_raw_str,reverse_raw_str),0)) over (partition by grp_id) -1 tail_len 
        FROM    t
        )
        , 
        t2 as 
        (SELECT id,
                grp_id,
                in_str, 
                utl_raw.substr(ref_raw_str,1,head_len) raw_head, 
                utl_raw.substr(reverse_ref_raw_str,1,tail_len) raw_tail 
        FROM    t1
        ) 
SELECT  id,
        grp_id,
        in_str, 
        utl_raw.cast_to_varchar2(raw_head)&#124;&#124;&#039;**&#039;&#124;&#124;utl_raw.cast_to_varchar2(utl_raw.reverse(raw_tail)) head_tail_pattern 
FROM    t2;

 ID  GRP_ID IN_STR               HEAD_TAIL_PATTERN
--- ------- -------------------- --------------------
  1      10 Fiveafpf1Three       Five**Three
  2      10 Five123zThree        Five**Three
  3      10 Five91OnezThree      Five**Three
  4      20 nine123TEN           nine**TEN
  5      20 nine345TEN           nine**TEN
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Well, here is another alternative (maybe not so elegant, but with supported packaged REVERSE function ) &#8211; using the table from previous example.</p>
<pre>
WITH t as
        (SELECT id,
                grp_id,
                in_str,
                min(in_str) over (partition by grp_id) ref_str,
                utl_raw.cast_to_raw(in_str) raw_str,
                utl_raw.cast_to_raw(min(in_str) over (partition by grp_id)) ref_raw_str,
                utl_raw.reverse(utl_raw.cast_to_raw(in_str)) reverse_raw_str,
                utl_raw.reverse(utl_raw.cast_to_raw(min(in_str) over (partition by grp_id))) reverse_ref_raw_str
        FROM    t5
        )
        ,
        t1 as
        (SELECT id,
                grp_id,
                in_str,
                ref_raw_str,
                reverse_ref_raw_str,
                min(nullif(utl_raw.compare(ref_raw_str,raw_str),0)) over(partition by grp_id)                  -1 head_len,
                min(nullif(utl_raw.compare(reverse_ref_raw_str,reverse_raw_str),0)) over (partition by grp_id) -1 tail_len
        FROM    t
        )
        ,
        t2 as
        (SELECT id,
                grp_id,
                in_str,
                utl_raw.substr(ref_raw_str,1,head_len) raw_head,
                utl_raw.substr(reverse_ref_raw_str,1,tail_len) raw_tail
        FROM    t1
        )
SELECT  id,
        grp_id,
        in_str,
        utl_raw.cast_to_varchar2(raw_head)||'**'||utl_raw.cast_to_varchar2(utl_raw.reverse(raw_tail)) head_tail_pattern
FROM    t2;

 ID  GRP_ID IN_STR               HEAD_TAIL_PATTERN
--- ------- -------------------- --------------------
  1      10 Fiveafpf1Three       Five**Three
  2      10 Five123zThree        Five**Three
  3      10 Five91OnezThree      Five**Three
  4      20 nine123TEN           nine**TEN
  5      20 nine345TEN           nine**TEN
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Laurent Schneider</title>
		<link>http://oraqa.com/2007/03/13/how-to-find-the-longest-common-substring-patterns-starting-from-the-string-headtail/comment-page-1/#comment-205</link>
		<dc:creator>Laurent Schneider</dc:creator>
		<pubDate>Wed, 21 Mar 2007 12:34:43 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2007/03/13/how-to-find-the-longest-common-substring-patterns-starting-from-the-string-headtail/#comment-205</guid>
		<description>note that REVERSE is not a supported function</description>
		<content:encoded><![CDATA[<p>note that REVERSE is not a supported function</p>
]]></content:encoded>
	</item>
</channel>
</rss>

