well, you can use instr(str, char, start_pos) to start
searching from a pos. This is going to end up being slow
especially for long strings.. You may want to do something
like this instead: (i just whipped this up so there
could be a typo or two)
PRAGMA RESTRICT_REFERENCES (count_chars,WNDS,WNPS);
function count_chars(pString in varchar2,
pChar in varchar2
pStartAt in number := 1,
pReadTo in number := null)
return number
cnt pls_integer := 0;
is
if pString is null then return 0;
for i in pStartAt .. length(pString) - nvl(pReadTo,0)
loop
if substr(pString, i, 1) = pChar then
cnt := cnt + 1;
end if;
end loop;
return cnt;
end;
-- you can then
-- select count_chars("abc def", " "

from dual .
.. Eat, think and be merry .
... ....................... .