Find tips oracle number of a character in a string

Oracle does not provide a lookup function of times a character appears in a string, when faced with such a demand, we can use other methods to achieve.

The idea is, assuming string str, then there are five characters a, 5 a when these characters removed, it is possible to obtain the remaining length of the string, with the original character string length by subtracting the remaining string length, get the number of characters of a:

LENGTH(STR) - LENGTH(REPLACE(STR, 'a', ''))

Let's try:

SELECT LENGTH('abcdabcdabcd') - LENGTH(REPLACE(STR, 'a', '')) A_COUNT FROM DUAL -- 3

This special technique to complete the original demand, the difference value by the function of the source string string using REPLACE ().

 

"Moments of beauty but the day enjoyable Whose homes,"

Guess you like

Origin www.cnblogs.com/yanggb/p/10820012.html