Reputation: 11
For Example: "Mahatma Gandhi" - how many A's are in the name ? I need a query for this. any help pls !
Upvotes: 1
Views: 936
Reputation: 14731
REGEX could be used to get the count of a letter in a string
SELECT REGEXP_COUNT ('Mahatma Gandhi', 'a') FROM DUAL;
For case-insensitive search
SELECT REGEXP_COUNT ('Mahatma Gandhi',
'A',
1,
'i')
REGEXP_COUNT
FROM DUAL;
Upvotes: 3
Reputation: 133370
You could try using length and replace
select length( 'Mahatma Gandhi') - length( replace('Mahatma Gandhi', 'a','')) num_char
from dual
Upvotes: 2