Oracle SQL 查找循环先决条件
Oracle SQL Find Circular Prerequisites
我有两个表,定义如下:
Course(Worker_id, Course_id)
Primary key is (Worker_id, Course_id)
Prerequisite(Course_id, Prerequisite_id)
Primary key is (Course_id, Prerequisite_id)
我希望能够找到所有循环先决条件。例如,如果 CourseA 是 CourseB 的先决条件,而 CourseB 是 CourseA 的先决条件(简化示例)。我的结果应该是具有不满足先决条件的课程的名称,在本例中为 CourseA 和 CourseB。
SELECT SYS_CONNECT_BY_PATH( Course_id, ' -> ' ) AS path
FROM prerequisites
WHERE CONNECT_BY_ISCYCLE = 1
CONNECT BY NOCYCLE
PRIOR Course_id = Prerequisite_id;
我有两个表,定义如下:
Course(Worker_id, Course_id)
Primary key is (Worker_id, Course_id)
Prerequisite(Course_id, Prerequisite_id)
Primary key is (Course_id, Prerequisite_id)
我希望能够找到所有循环先决条件。例如,如果 CourseA 是 CourseB 的先决条件,而 CourseB 是 CourseA 的先决条件(简化示例)。我的结果应该是具有不满足先决条件的课程的名称,在本例中为 CourseA 和 CourseB。
SELECT SYS_CONNECT_BY_PATH( Course_id, ' -> ' ) AS path
FROM prerequisites
WHERE CONNECT_BY_ISCYCLE = 1
CONNECT BY NOCYCLE
PRIOR Course_id = Prerequisite_id;