Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Personally, in this situation, I would choose PL/SQL code over plain SQL. Something like:</p> <p>Package specification:</p> <pre><code>create or replace package PKG is function NumOfSeqWords( p_str1 in varchar2, p_str2 in varchar2 ) return number; end; </code></pre> <p>Package body:</p> <pre><code>create or replace package body PKG is function NumOfSeqWords( p_str1 in varchar2, p_str2 in varchar2 ) return number is l_str1 varchar2(4000) := p_str1; l_str2 varchar2(4000) := p_str2; l_res number default 0; l_del_pos1 number; l_del_pos2 number; l_word1 varchar2(1000); l_word2 varchar2(1000); begin loop l_del_pos1 := instr(l_str1, ' '); l_del_pos2 := instr(l_str2, ' '); case l_del_pos1 when 0 then l_word1 := l_str1; l_str1 := ''; else l_word1 := substr(l_str1, 1, l_del_pos1 - 1); end case; case l_del_pos2 when 0 then l_word2 := l_str2; l_str2 := ''; else l_word2 := substr(l_str2, 1, l_del_pos2 - 1); end case; exit when (l_word1 &lt;&gt; l_word2) or ((l_word1 is null) or (l_word2 is null)); l_res := l_res + 1; l_str1 := substr(l_str1, l_del_pos1 + 1); l_str2 := substr(l_str2, l_del_pos2 + 1); end loop; return l_res; end; end; </code></pre> <p>Test case:</p> <pre><code> with t1(Id1, col1, col2) as( select 1, 'foo bar live' ,'foo bar' from dual union all select 2, 'foo live tele' ,'foo tele' from dual union all select 3, 'bar foo live' ,'foo bar live'from dual ) select id1 , col1 , col2 , pkg.NumOfSeqWords(col1, col2) as res from t1 ; </code></pre> <p>Result:</p> <pre><code> ID1 COL1 COL2 RES ---------- ------------- ------------ ---------- 1 foo bar live foo bar 2 2 foo live tele foo tele 1 3 bar foo live foo bar live 0 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload