0

How can i count the number of 'a' in the string 'rajarajeshwari'

I want count of 'a' in that string

Jonas Metzler
  • 4,517
  • 1
  • 5
  • 17
  • 3
    Why do people not google a solution before asking a question here? Question and answer here are a pure duplicate, see: [How to count the number of occurrences of a character in an Oracle varchar value?](https://stackoverflow.com/questions/8169471/how-to-count-the-number-of-occurrences-of-a-character-in-an-oracle-varchar-value) Using google, this is the first result of the search "oracle count letters in string" – Jonas Metzler Dec 23 '22 at 05:26

1 Answers1

2

You can try like this

select length('rajarajeshwari') - length(replace('rajarajeshwari','a',null)) 
from dual;

DEMO

or you can also use the REGEXP_COUNT function

select REGEXP_COUNT('rajarajeshwari', 'a') from dual;

DEMO

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331