create a shortest code function to count no of vowels in a string?

Oracle Application Express is a rapid development tool for Web applications on the Oracle database.
Post Reply
admin
Posts: 2073
Joined: Fri Mar 31, 2006 12:59 am
Location: Pakistan
Contact:

create a shortest code function to count no of vowels in a string?

Post by admin »

Here was a challenge of problem solcing given to our APEX community and here are answers,

Try to create a shortest code function to count no of vowels in a string and return count using Oracle PLSQL. Improving problem solving and logic building. enjoy

Code: Select all

CREATE OR REPLACE FUNCTION fraz.count_vowels(input_string VARCHAR2) RETURN NUMBER IS
    Vcount NUMBER := 0;
BEGIn
    FOR i IN 1..LENGTH(input_string) LOOP
        IF UPPER(SUBSTR(input_string, i, 1)) IN ('A', 'E', 'I', 'O', 'U') THEN
            Vcount := Vcount + 1;
        END IF;
    END LOOP;

    RETURN Vcount;
END ;
/

DECLARE
    v_input_string VARCHAR2(500) := 'Muhammad Fraz Dba';
    v_result NUMBER;
BEGIN
    v_result := fraz.count_vowels(v_input_string);
    DBMS_OUTPUT.PUT_LINE('Number of vowels count: ' || v_result);
END;
/

Number of vowels count: 5

Code: Select all

SELECT REGEXP_COUNT(UPPER('ABCDI'), 'A|E|I|O|U') REGEXP_COUNT
FROM DUAL;
Malik Sikandar Hayat
Oracle ACE Pro
info@erpstuff.com
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests