Siva Academy

Youtube.com/SivaAcademy  Oracle SQL  |  PLSQL  |  SQL PLSQL Interview Questions  |  PLSQL Scenario based Interview Questions  |  Subscriber Questions & Answers

  |  SQL practical Question  |  SQL Performance Tuning  |  New Features  |  

  Trigger     |    View  

Tuesday, August 11, 2020

SQL to count number of vowels

SQL to count number of occurrences of a vowels


create table emp(empno number,ename varchar2(100));


WITH ds AS (

    SELECT empno,

           upper(ename)      ename,

           length(ename)     l

    FROM emp)

SELECT *

FROM

    (

        SELECT empno,ename,c,COUNT(*) cnt

        FROM

            (

                SELECT empno, ename,substr(ename, r, 1) c

                FROM

                    ds,

                    LATERAL ( SELECT ROWNUM r

                              FROM dual

                              CONNECT BY level <= l)

            )

        WHERE

            c IN ('A','E','I','O','U')

        GROUP BY empno,ename,c

    ) PIVOT ( MAX ( cnt ) FOR c IN ( 'A','E','I','O','U' ));

8 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. We are one of the authorized people for bus branding in Chennai metropolitan and across Tamilnadu.

    Bus Advertising Agency in Chennai

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. SELECT
    string_column,
    LENGTH(string_column) - LENGTH(REPLACE(LOWER(string_column), 'a', '')) AS count_a,
    LENGTH(string_column) - LENGTH(REPLACE(LOWER(string_column), 'e', '')) AS count_e,
    LENGTH(string_column) - LENGTH(REPLACE(LOWER(string_column), 'i', '')) AS count_i,
    LENGTH(string_column) - LENGTH(REPLACE(LOWER(string_column), 'o', '')) AS count_o,
    LENGTH(string_column) - LENGTH(REPLACE(LOWER(string_column), 'u', '')) AS count_u
    FROM
    table_data;

    ReplyDelete