Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is is possible to count the number of occurrences of a character in a VARCHAR in oracle? Something that would allow me to determine '11001110' has 5 ones?

share|improve this question
up vote 7 down vote accepted

What version of Oracle?

If you're using Oracle 11.1 or later, you can use REGEXP_COUNT

  1* select regexp_count( '11001110', '1' ) from dual
SQL> /


In earlier versions, there are various less elegant options such as

SQL> select length( '11001110' ) - length( replace( '11001110', '1' ) ) cnt
  2    from dual;

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.