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;