declare
v_1 number := 0;
v_pattern VARCHAR(26) := '&n';
v_f number;
v_spaces VARCHAR(30) := ' ';
v_l number;
v_c varchar(20) := ' ';
v_n varchar(20) := ' ';
BEGIN
v_f := Ascii(SubStr(v_pattern,1,1));
v_l := Ascii(SubStr(v_pattern,Length(v_pattern)));
v_spaces := LPad(' ',Length(v_pattern),' ');
for i in (select str,TRANSLATE(REPLACE(str,' ',''),v_pattern,v_spaces) c1,length(REPLACE(str,' ',''))-nvl(length(replace(TRANSLATE(REPLACE(str,' ',''),v_pattern,v_spaces),' ','')),0) c2 from table
where ascii(substr(str,1,1)) IN (SELECT DISTINCT Ascii(SubStr(v_pattern,LEVEL,1)) FROM dual CONNECT BY LEVEL<=Length(v_pattern))) loop
for j in 1..i.c2 loop
v_c :=instr(i.c1,' ',1,j);
v_n :=instr(i.c1,' ',1,j+1);
if v_c+1=v_n then
v_1 := v_1+1;
end if;
end loop;
if(v_1+1 = i.c2) then
dbms_output.put_line('String : '||i.str||' and Matching count : '||i.c2);
else
dbms_output.put_line('String : '||i.str||' and Matching count : '||((v_1)-1));
end if;
v_1 := 0;
end loop;
FOR k IN (SELECT str FROM table WHERE NOT(Ascii(substr(str,1,1)) IN (SELECT DISTINCT Ascii(SubStr(v_pattern,LEVEL,1)) FROM dual CONNECT BY LEVEL<=Length(v_pattern)))) LOOP
dbms_output.put_line('String : '||k.str||' and Matching count : '||v_1);
END LOOP;
end;