Oracle 递归查询

Oracle 递归查询

###1. 递归向下追溯

1.1 E_ASSOCIATEDCONTAINERID ParentId
1.2 CONTAINERID ChildId
1.3 Sql语句

```sql
SELECT a.*  FROM 
CONTAINER a
WHERE
	1=1
START WITH	a.Id='4220202206132210'
CONNECT BY PRIOR a.Id=a.ParentId;--

```sql
SELECT b.CONTAINERLEVELNAME,a.CONTAINERNAME FROM 
CONTAINER a
inner join CONTAINERLEVEL b on a.LEVELID=b.CONTAINERLEVELID
WHERE
	1=1
START WITH	a.CONTAINERNAME='4220202206132210'
CONNECT BY PRIOR a.CONTAINERID=a.E_ASSOCIATEDCONTAINERID;--SCPXSJ20220613CW0002

2.向上递归

2.1 Sql示例

```sql
SELECT a.*  FROM 
CONTAINER a
WHERE
	1=1
START WITH	a.Id='4220202206132210'
CONNECT BY PRIOR a.ParentId=a.I;

```sql

```sql
SELECT b.CONTAINERLEVELNAME,a.CONTAINERNAME FROM 
CONTAINER a
inner join CONTAINERLEVEL b on a.LEVELID=b.CONTAINERLEVELID
WHERE
	1=1
START WITH	a.CONTAINERNAME='SCPXSJ20220613CW0002'
CONNECT BY PRIOR a.E_ASSOCIATEDCONTAINERID=a.CONTAINERID;

你可能感兴趣的:(Oracle,oracle,数据库)