No. of vowels and consonants in a given string in PL/SQL Last Updated : 05 Jul, 2018 Comments Improve Suggest changes Like Article Like Report Prerequisite - PL/SQL introduction In PL/SQL code groups of commands are arranged within a block. A block group related declarations or statements. In declare part, we declare variables and between begin and end part, we perform the operations. Given a string and the task is to find the number of vowels and consonants present in the string. Examples: Input: str = 'Ramesh' Output: Vowels = 2, Consonants = 4 Input: str = 'Ramesh is a Geek' Output: Vowels = 6, Consonants = 7 Approach is to consider a character one by one and maintain a separate count for both vowels and consonants. Below is the required implementation: SQL DECLARE -- Here variable V is varchar datatype -- and flag variable is number datatype -- variable c is char datatype . v VARCHAR2(400) := 'Ramesh is a Geek'; noofvowels NUMBER := 0; noofconsonants NUMBER := 0; C CHAR; BEGIN FOR i IN 1..Length(v) LOOP c := Substr(v, i, 1); -- Check if the current character is vowel IF c IN ( 'A', 'E', 'I', 'O', 'U' ) OR c IN ( 'a', 'e', 'i', 'o', 'u' ) THEN noofvowels := noofvowels + 1; -- Else current character is a consonant except space ELSE IF c NOT IN ( ' ' ) THEN noofconsonants := noofconsonants + 1; END IF; END IF; END LOOP; dbms_output.Put_line('No. of Vowels: ' || noofvowels); dbms_output.Put_line('No. of Consonants: ' || noofconsonants); END; -- Program End Output : No. of Vowels: 6 No. of Consonants: 7 Comment More infoAdvertise with us Next Article No. of vowels and consonants in a given string in PL/SQL S Shashank12 Follow Improve Article Tags : Misc SQL SQL-PL/SQL Practice Tags : Misc Similar Reads Count no. of characters and words in a string in PL/SQL Prerequisite - PL/SQL introduction In PL/SQL code groups of commands are arranged within a block. A block group related declarations or statements. In declare part, we declare variables and between begin and end part, we perform the operations. Given a string and the task is to count the number of c 2 min read Concatenation of strings in PL/SQL Prerequisite - PL/SQL Introduction In PL/SQL code groups of commands are arranged within a block. A block group related declarations or statements. In declare part, we declare variables and between begin and end part, we perform the operations. Given two strings and the task is to concatenate them a 1 min read Replace all consonants with nearest vowels in a string Given a string with lowercase English alphabets. The task is to replace all the consonants in the string with the nearest vowels. If a consonant is near to two vowels then replace it with the one that comes first in English alphabets. Note: Vowels already present in the string must be left as it is. 10 min read Encrypt string with product of number of vowels and consonants in substring of size k Given a string s and a positive integer k. You need to encrypt the given string such that each substring of size k is represented by an integer, which is obtained by the product of number of vowels and number of consonants in the substring. Examples: Input : s = "hello", k = 2 Output : 1101 k = 2, s 13 min read Count of substrings consisting of even number of vowels Given a string S of length N, the task is to find the number of non-empty substrings having even number of vowels. Examples: Input: N = 5, S = "abcde"Output: 7Explanation: All possible substrings with even number of vowels are:Substring Vowels{abcde} 2{b} 0{bc} 0{bcd} 0{c} 0{cd} 0{d} 0Input: N=4, S= 11 min read Like