0

我有一个查询,包括按先验连接;

SELECT SYS_CONNECT_BY_PATH(ENAME, '/') as path
FROM EMP
WHERE CONNECT_BY_ISLEAF=1
START WITH MGR IS NULL CONNECT BY
PRIOR EMPNO=MGR;

结果如下

 path
-----------------------------------
/KING/JONES/SCOTT/ADAMS
/KING/BLAKE/ALLEN
/KING/BLAKE/WARD
/KING/BLAKE/MARTIN
/KING/BLAKE/TURNER
/KING/BLAKE/JAMES
/KING/CLARK/MILLER

现在我想将正则表达式(Oracle 中的 REGEXP_LIKE)应用于路径列以通过“/KING/JONE”查找“/KING/JONES/SCOTT/ADAMS”。

有没有办法做到这一点?

提前致谢

4

1 回答 1

2

使用 CTE:

with t as (
  SELECT SYS_CONNECT_BY_PATH(ENAME, '/') as path
  FROM EMP
  WHERE CONNECT_BY_ISLEAF=1
  START WITH MGR IS NULL CONNECT BY
  PRIOR EMPNO=MGR
)
select *
from t
where path like '/KING/JONE%';

(在你的例子中,like会做得很好 - 而且比 更快regexp_like

于 2016-10-26T11:27:12.073 回答