I have done this question by two methods
- By using loops
declare
counts number :=0;
counts1 number :=0;
str1 varchar2(500) :=LOWER('This is the string');
begin
for i in 1..length(str1)
loop
if(substr(str1,i,1) in ('a','e','i','o','u'))
then
counts := counts + 1;
else
counts1 := counts1 + 1;
end if;
end loop;
dbms_output.put_line('Input : '||str1);
dbms_output.put_line('Total vovels :' ||counts);
dbms_output.put_line('Total consonants :' ||counts1);
end;
- By using regular expressions
declare
counts number := 0;
counts1 number := 0;
str1 varchar2(500) := lower('This is the string');
begin
select length(regexp_replace(str1,'[^aeiou]')) as total_vovels into counts from dual;
select length(regexp_replace(str1,'[aeiou]')) as total_consonants into counts1 from dual;
dbms_output.put_line('Total vovels :'||counts);
dbms_output.put_line('Total consonants :'||counts1);
end;
No comments:
Post a Comment