求助,删除数据库父节点及父节点下的所有子节点
2015-07-23
展开全部
主要是分层查询,sql脚本如下:
CREATE TABLE TEST_A (ID NUMBER,PID NUMBER)
INSERT INTO TEST_A
VALUES(1,0);
COMMIT;
INSERT INTO TEST_A
VALUES(2,1);
COMMIT;
INSERT INTO TEST_A
VALUES(3,1);
COMMIT;
INSERT INTO TEST_A
VALUES(4,2);
COMMIT;
INSERT INTO TEST_A
VALUES(5,2);
COMMIT;
INSERT INTO TEST_A
VALUES(6,3);
COMMIT;
INSERT INTO TEST_A
VALUES(7,4);
COMMIT;
INSERT INTO TEST_A
VALUES(8,5);
COMMIT;
SELECT *
FROM TEST_A A
START WITH A.PID = 0
CONNECT BY PRIOR A.ID = A.PID
ORDER BY A.PID;
希望能帮到你。
CREATE TABLE TEST_A (ID NUMBER,PID NUMBER)
INSERT INTO TEST_A
VALUES(1,0);
COMMIT;
INSERT INTO TEST_A
VALUES(2,1);
COMMIT;
INSERT INTO TEST_A
VALUES(3,1);
COMMIT;
INSERT INTO TEST_A
VALUES(4,2);
COMMIT;
INSERT INTO TEST_A
VALUES(5,2);
COMMIT;
INSERT INTO TEST_A
VALUES(6,3);
COMMIT;
INSERT INTO TEST_A
VALUES(7,4);
COMMIT;
INSERT INTO TEST_A
VALUES(8,5);
COMMIT;
SELECT *
FROM TEST_A A
START WITH A.PID = 0
CONNECT BY PRIOR A.ID = A.PID
ORDER BY A.PID;
希望能帮到你。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询