Yes, it is possible with CONNECT BY. However a little harder:
SELECT xchar, xcount FROM (
SELECT xchar, COUNT(*) AS xcount, RANK() OVER ( ORDER BY COUNT(*) DESC) AS rn
FROM (
SELECT SUBSTR('aaaabcd', LEVEL, 1) AS xchar
FROM dual
CONNECT BY LEVEL <= LENGTH('aaaabcd')
) GROUP BY xchar
) WHERE rn = 1;
What we do in the innermost query breaks the string into separate characters. Then we just get COUNT(), grouped by character, and use RANK()max to find it (note that this will return more than one result if there is a relationship for the most common character).
, , , .
, - :
WITH strlen AS (
SELECT LEVEL AS strind
FROM dual
CONNECT BY LEVEL <= 30
)
SELECT id, xchar, xcount FROM (
SELECT id, xchar, COUNT(*) AS xcount, RANK() OVER ( PARTITION BY id ORDER BY COUNT(*) DESC) AS rn
FROM (
SELECT s.id, SUBSTR(s.str, sl.strind, 1) AS xchar
FROM strings s, strlen sl
WHERE LENGTH(s.str) >= sl.strind
) GROUP BY id, xchar
) WHERE rn = 1;
30 - , . . SQL Fiddle. , :
WITH strlen AS (
SELECT LEVEL AS strind
FROM dual
CONNECT BY LEVEL <= ( SELECT MAX(LENGTH(str)) FROM strings )
)
SELECT id, xchar, xcount FROM (
SELECT id, xchar, COUNT(*) AS xcount, RANK() OVER ( PARTITION BY id ORDER BY COUNT(*) DESC) AS rn
FROM (
SELECT s.id, SUBSTR(s.str, sl.strind, 1) AS xchar
FROM strings s, strlen sl
WHERE LENGTH(s.str) >= sl.strind
) GROUP BY id, xchar
) WHERE rn = 1;
SQL.