SQL Tutorial

SQL Clauses / Operators

SQL-Injection

SQL Functions

SQL Queries

PL/SQL

MySQL

SQL Server

Misc

No. of vowels and consonants in a given string in PL/SQL

To determine the number of vowels and consonants in a given string using PL/SQL, you can create a PL/SQL block that:

  1. Iterates through each character of the string.
  2. Checks if the character is a vowel or a consonant.
  3. Increments the respective count based on the character type.

Here's a simple PL/SQL block to do this:

DECLARE
    input_string VARCHAR2(100) := 'YourInputStringHere';
    char_char CHAR(1);
    vowels_count NUMBER := 0;
    consonants_count NUMBER := 0;
BEGIN
    FOR i IN 1..LENGTH(input_string) LOOP
        char_char := UPPER(SUBSTR(input_string, i, 1)); -- Convert to uppercase for simplicity

        -- Check if character is a vowel
        IF char_char IN ('A', 'E', 'I', 'O', 'U') THEN
            vowels_count := vowels_count + 1;
        ELSIF char_char BETWEEN 'A' AND 'Z' THEN -- If it's an uppercase alphabet but not a vowel, then it's a consonant
            consonants_count := consonants_count + 1;
        END IF;
    END LOOP;

    DBMS_OUTPUT.PUT_LINE('Number of vowels: ' || vowels_count);
    DBMS_OUTPUT.PUT_LINE('Number of consonants: ' || consonants_count);
END;
/

Replace 'YourInputStringHere' with the string you want to analyze. This block will display the number of vowels and consonants in the provided string.

Note that this code considers only the English alphabets and doesn't account for other characters, numbers, or symbols in the string. You might need to adjust the code if you need more extensive character set handling.

  1. PL/SQL program to count vowels and consonants in a string:

    • A PL/SQL program to count vowels and consonants in a given string.
    DECLARE
       str VARCHAR2(100) := 'YourStringHere';
       vowel_count INT := 0;
       consonant_count INT := 0;
    BEGIN
       FOR i IN 1..LENGTH(str) LOOP
          IF UPPER(SUBSTR(str, i, 1)) IN ('A', 'E', 'I', 'O', 'U') THEN
             vowel_count := vowel_count + 1;
          ELSIF REGEXP_LIKE(SUBSTR(str, i, 1), '[A-Z]') THEN
             consonant_count := consonant_count + 1;
          END IF;
       END LOOP;
    
       DBMS_OUTPUT.PUT_LINE('Vowel Count: ' || vowel_count);
       DBMS_OUTPUT.PUT_LINE('Consonant Count: ' || consonant_count);
    END;
    
  2. Oracle SQL function for counting vowels and consonants:

    • An Oracle SQL function to count vowels and consonants in a string.
    CREATE OR REPLACE FUNCTION count_vowels_consonants(p_str VARCHAR2)
       RETURN VARCHAR2
    AS
       vowel_count INT := 0;
       consonant_count INT := 0;
    BEGIN
       FOR i IN 1..LENGTH(p_str) LOOP
          IF UPPER(SUBSTR(p_str, i, 1)) IN ('A', 'E', 'I', 'O', 'U') THEN
             vowel_count := vowel_count + 1;
          ELSIF REGEXP_LIKE(SUBSTR(p_str, i, 1), '[A-Z]') THEN
             consonant_count := consonant_count + 1;
          END IF;
       END LOOP;
    
       RETURN 'Vowel Count: ' || TO_CHAR(vowel_count) || ', Consonant Count: ' || TO_CHAR(consonant_count);
    END count_vowels_consonants;
    
  3. Calculate number of vowels and consonants in a string using PL/SQL:

    • Another PL/SQL program to calculate the number of vowels and consonants in a given string.
    DECLARE
       str VARCHAR2(100) := 'YourStringHere';
       vowel_count INT := 0;
       consonant_count INT := 0;
    BEGIN
       FOR i IN 1..LENGTH(str) LOOP
          IF UPPER(SUBSTR(str, i, 1)) IN ('A', 'E', 'I', 'O', 'U') THEN
             vowel_count := vowel_count + 1;
          ELSIF REGEXP_LIKE(SUBSTR(str, i, 1), '[A-Z]') THEN
             consonant_count := consonant_count + 1;
          END IF;
       END LOOP;
    
       DBMS_OUTPUT.PUT_LINE('Vowel Count: ' || vowel_count);
       DBMS_OUTPUT.PUT_LINE('Consonant Count: ' || consonant_count);
    END;
    
  4. PL/SQL procedure for string analysis - vowels and consonants:

    • A PL/SQL procedure for analyzing a string and counting vowels and consonants.
    CREATE OR REPLACE PROCEDURE analyze_string(p_str IN VARCHAR2)
    AS
       vowel_count INT := 0;
       consonant_count INT := 0;
    BEGIN
       FOR i IN 1..LENGTH(p_str) LOOP
          IF UPPER(SUBSTR(p_str, i, 1)) IN ('A', 'E', 'I', 'O', 'U') THEN
             vowel_count := vowel_count + 1;
          ELSIF REGEXP_LIKE(SUBSTR(p_str, i, 1), '[A-Z]') THEN
             consonant_count := consonant_count + 1;
          END IF;
       END LOOP;
    
       DBMS_OUTPUT.PUT_LINE('Vowel Count: ' || vowel_count);
       DBMS_OUTPUT.PUT_LINE('Consonant Count: ' || consonant_count);
    END analyze_string;
    
  5. Counting letters in a string in PL/SQL:

    • A PL/SQL program to count all letters (including vowels and consonants) in a given string.
    DECLARE
       str VARCHAR2(100) := 'YourStringHere';
       letter_count INT := 0;
    BEGIN
       FOR i IN 1..LENGTH(str) LOOP
          IF REGEXP_LIKE(SUBSTR(str, i, 1), '[A-Z]') THEN
             letter_count := letter_count + 1;
          END IF;
       END LOOP;
    
       DBMS_OUTPUT.PUT_LINE('Letter Count: ' || letter_count);
    END;
    
  6. Oracle SQL query to find vowel count in a string:

    • An Oracle SQL query to find the vowel count in a given string.
    SELECT
       LENGTH(REGEXP_REPLACE('YourStringHere', '[AEIOU]', '')) AS VowelCount
    FROM dual;
    
  7. PL/SQL function to determine vowels and consonants in a text:

    • A PL/SQL function that returns the count of vowels and consonants in a given text.
    CREATE OR REPLACE FUNCTION count_vowels_consonants(p_text VARCHAR2)
       RETURN VARCHAR2
    AS
       vowel_count INT := 0;
       consonant_count INT := 0;
    BEGIN
       FOR i IN 1..LENGTH(p_text) LOOP
          IF UPPER(SUBSTR(p_text, i, 1)) IN ('A', 'E', 'I', 'O', 'U') THEN
             vowel_count := vowel_count + 1;
          ELSIF REGEXP_LIKE(SUBSTR(p_text, i, 1), '[A-Z]') THEN
             consonant_count := consonant_count + 1;
          END IF;
       END LOOP;
    
       RETURN 'Vowel Count: ' || TO_CHAR(vowel_count) || ', Consonant Count: ' || TO_CHAR(consonant_count);
    END count_vowels_consonants;
    
  8. String manipulation in PL/SQL for vowel and consonant analysis:

    • PL/SQL code for string manipulation to analyze vowels and consonants in a given string.
    DECLARE
       str VARCHAR2(100) := 'YourStringHere';
       vowel_count INT := 0;
       consonant_count INT := 0;
    BEGIN
       FOR i IN 1..LENGTH(str) LOOP
          IF UPPER(SUBSTR(str, i, 1)) IN ('A', 'E', 'I', 'O', 'U') THEN
             vowel_count := vowel_count + 1;
          ELSIF REGEXP_LIKE(SUBSTR(str, i, 1), '[A-Z]') THEN
             consonant_count := consonant_count + 1;
          END IF;
       END LOOP;
    
       DBMS_OUTPUT.PUT_LINE('Vowel Count: ' || vowel_count);
       DBMS_OUTPUT.PUT_LINE('Consonant Count: ' || consonant_count);
    END;
    
  9. Oracle SQL script to count vowels and consonants in a sentence:

    • An Oracle SQL script to count vowels and consonants in a sentence.
    DECLARE
       sentence VARCHAR2(200) := 'Your sentence goes here.';
       vowel_count INT := 0;
       consonant_count INT := 0;
    BEGIN
       FOR i IN 1..LENGTH(sentence) LOOP
          IF UPPER(SUBSTR(sentence, i, 1)) IN ('A', 'E', 'I', 'O', 'U') THEN
             vowel_count := vowel_count + 1;
          ELSIF REGEXP_LIKE(SUBSTR(sentence, i, 1), '[A-Z]') THEN
             consonant_count := consonant_count + 1;
          END IF;
       END LOOP;
    
       DBMS_OUTPUT.PUT_LINE('Vowel Count: ' || vowel_count);
       DBMS_OUTPUT.PUT_LINE('Consonant Count: ' || consonant_count);
    END;
    
  10. Finding character count in PL/SQL including vowels and consonants:

    • PL/SQL code to find the character count, including vowels and consonants, in a given string.
    DECLARE
       str VARCHAR2(100) := 'YourStringHere';
       character_count INT := 0;
    BEGIN
       FOR i IN 1..LENGTH(str) LOOP
          IF REGEXP_LIKE(SUBSTR(str, i, 1), '[A-Z]') THEN
             character_count := character_count + 1;
          END IF;
       END LOOP;
    
       DBMS_OUTPUT.PUT_LINE('Character Count: ' || character_count);
    END;