Hi,

MySQL dosen't have built-in function for counting substring. But we can create user-defined functions for this.
Like,

CREATE FUNCTION substrCount(x varchar(255), delim varchar(12)) returns int
return (length(x)-length(REPLACE(x, delim, '')))/length(delim);

Then try,

SELECT substrCount('Characteristics', 'c') as count;
which returns 3.

For more reference http://dev.mysql.com/doc/refman/5.0/en/string-functions.html

Thanks,
ViSolve DB Team.
----- Original Message ----- From: "Scott Hamm" <[EMAIL PROTECTED]>
To: "'Mysql '" <mysql@lists.mysql.com>
Sent: Tuesday, October 10, 2006 10:58 PM
Subject: Counting char in a column


I'm running MySQL 5.0.15 on Windows system.

How do I count how many specific char is there in a column, for example
finding 'c' in lowercase string of "Characteristics" would total to 3.




--
--------------------------------------------------------------------
`Twas brillig, and the slithy toves
Did gyre and gimble in the wabe:
All mimsy were the borogoves,
And the mome raths outgrabe.
--------------------------------------------------------------------



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to