Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
create or replace function how_many (search_str in varchar, whole_str in varchar)
return number is
begin
return (length(whole_str)-Length(replace(whole_str,search_str,null)))/
length(search_str);
end;
/
col x heading "How|Many|Commas" format 99
select how_many(',','12,3,45,99') x from dual;
How
Many
Commas
------
3
col "a's" format 999
select last_name,how_many('a',last_name)"a's" from s_emp
where rownum <= 5
LAST_NAME a's
--------------- ----
Garcia 2
Ngao 1
Nagayama 4
Quick-To-See 0
Ropeburn 0
col x heading "How|Many|'efg'|strings" format 999
select how_many('def','abcdefgabcdefg123123')x from dual
How
Many
'efg'
strings
-------
2
/*==================================================*/
/* Function to return the number of times that a */
/* search string is found inside a text string */
/* */
/* Example: */
/* select HOW_MANY('AN','MAN CAN STAND') from DUAL; */
/* -- -- -- */
/* Returns 3 (three 'AN's in 'MAN CAN STAND') */
/* */
/* Calculated: */
/* Length of text */
/* - (Length of text w/search string removed) */
/* divided by the length of the search text */
/* (13 - 7) / 2 = 3 */
/*==================================================*/