# Re: find out how many times particular character occur in given string.

Date: Wed, 10 Dec 2008 22:26:17 -0600

Message-ID: <RD00l.7277$W06.4682@flpi148.ffdc.sbc.com>

Michel Cadot wrote:

*> "Sanjeev" <sanjeev.atvankar_at_gmail.com> a écrit dans le message de news: *

*> 6e2ea0b9-5782-4945-962c-5c7de86dde9b_at_k36g2000pri.googlegroups.com...*

*> | Dear Gurus,*

*> |*

*> | I want to find out how many times particular character occur in*

*> | given string.*

*> | e.g. 'A*B*C*D*E*F' count of '*' is 5*

*> | 'A*B*C*D' count of '*' is 3*

*> | 'A' count of '*' is 0*

*> |*

*> | Is there any function available in SQL to find out the above*

*> | requirement ?*

*> |*

*> | Could anyone help me in above?*

*> |*

*> | Thanking in advance*

*> | Sanjeev*

*> *

*> SQL> def str='A*B*C*D*E*F'*

*> SQL> def car='*'*

*> SQL> select length('&str')-length(replace('&str','&car')) nb from dual;*

*> NB*

*> ----------*

*> 5*

*> *

*> 1 row selected.*

*> *

*> SQL> def str='A*B*C*D'*

*> SQL> /*

*> NB*

*> ----------*

*> 3*

*> *

*> 1 row selected.*

*> *

*> SQL> def str='A'*

*> SQL> /*

*> NB*

*> ----------*

*> 0*

*> *

*> 1 row selected.*

*> *

*> Regards*

*> Michel*

*> *

*> *

nice - exact same question and answer in the MySQL NG. [eg. CHAR_LENGTH(myfield)-CHAR_LENGTH(REPLACE(myfield,'*','')) ]

The OP should cross-post - not multi-post and if he doesn't understand the difference should use google to figure it out... Received on Wed Dec 10 2008 - 22:26:17 CST