Count of vowels in a sting in oracle
In oracle 10 g we can do this by
SELECT length('akhil')
- length(REGEXP_REPLACE('akhil','[a,e,i,o,u,A,E,I,O,U]','')) FROM DUAL;
In oracle 11g we can simplify this code to
SELECT REGEXP_COUNT('akhil','[a,e,i,o,u,A,E,I,O,U]' ) from dual
We can do this in any of the versions like 9i,10g,11g etc.. by
Select length('akhil')-length(translate('akhil','zaeiouAEIOU',z) ) from dual
The operation of the abouve statement is like below
It will translate the each existance of 'z ' with z,because of there is nothing to be specified to replace for a,e,i,o,u,A,E,I,O,U . It will find the count of that. Reduce the count of this from the total length of the string . That is length of string -length of non vowel elements.
SELECT length('akhil')
- length(REGEXP_REPLACE('akhil','[a,e,i,o,u,A,E,I,O,U]','')) FROM DUAL;
In oracle 11g we can simplify this code to
SELECT REGEXP_COUNT('akhil','[a,e,i,o,u,A,E,I,O,U]' ) from dual
We can do this in any of the versions like 9i,10g,11g etc.. by
Select length('akhil')-length(translate('akhil','zaeiouAEIOU',z) ) from dual
The operation of the abouve statement is like below
It will translate the each existance of 'z ' with z,because of there is nothing to be specified to replace for a,e,i,o,u,A,E,I,O,U . It will find the count of that. Reduce the count of this from the total length of the string . That is length of string -length of non vowel elements.
Comments
Post a Comment