1

I have to get from first name and last name how many times is mentioned the word " A" with the condition that is has to be mention more than 10 times. For example : 1. Alessandra Antatarovich Alatatatovica 2. Aaron Aaaantonich Albachiara .....

Expected result is :

                    `First_name             Last_name            Count`

                     Alessandra Antatarovich Alatatatovica        11
                     Aaron     Aaaantonich   Albachiaraaa         12
                     AAAAcc                 ABCDAAAAAAAAA         14 

Name of the table is Client

If there is a name and last name with only 8 " A" than that record will not display.. If there is a record for example First name : AAABBBAAANHDHD and Last name : BBAAAAAAATK that has 13 " A" than this record will appear

2 Answers2

2

Oracle has the regexp_count() function for this purpose.

The basic syntax is:

select regexp_count(FirstName || LastName, 'A')

For the condition of 10, then something like:

select c.*, regexp_count(FirstName || LastName, 'A')
from client c
where  regexp_count(FirstName || LastName, 'A') > 10;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

and if no rexexp_count() in your SQL - you can use this simple trick:

select *, 
length(concat(First_name,Last_name))- length(substitue(concat(First_name,Last_name),'A','') as 'Acount'
from tableName
having Acount>10
Zahiro Mor
  • 1,708
  • 1
  • 16
  • 30