Il * l'operatore è 'greedy' per impostazione predefinita
. Stai consentendo qualsiasi carattere tra distinct e ) , in qualsiasi quantità. e compreso il primo ) stesso.
Come suggerito da EatÅPeach, puoi renderlo non avido con ? :
Quindi qui, con .*? invece di .* :
select regexp_substr(
'select count(distinct empno), count(distinct deptno) from emp',
'count\(distinct.*?\)')
from dual;
Oppure puoi specificare che dovrebbe essere qualsiasi carattere tranne ) con [^)]* invece di .* .
select regexp_substr(
'select count(distinct empno), count(distinct deptno) from emp',
'count\(distinct[^)]*\)')
from dual;