Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Research on Oracle Tree query (start with connect by prior)

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The most important syntax structure of an oracle tree query is: select. Start with... Connect by... Prior, which allows you to display the relationships in the table as a tree.

1. Create test tables and data:

-- create a test table

CREATE TABLE YAG_TREE (

T_ID NUMBER (10) NOT NULL-- id

T_CONTEXT VARCHAR2 (20)-- content

PARENTID NUMBER (10)-parent id

);

-- create a sequence

CREATE SEQUENCE SEQ_YAG START WITH 1 MAXVALUE 100 INCREMENT BY 1 NOCYCLE CACHE 10

-- generate parent node data

BEGIN

FOR I IN 1..5 LOOP

INSERT INTO YAG_TREE VALUES (SEQ_YAG.NEXTVAL,' parent node'| | SEQ_YAG.CURRVAL,NULL)

COMMIT

END LOOP

END

-- generate first-level node data

BEGIN

FOR I IN 1..15 LOOP

IF I level 1 Node 7 7 Tier 1 Node 7 1

3 parent node 1 murmurs-> first level node 7 murmurs-> secondary nodes 22 22 secondary nodes 22 7

2 parent node 1 murmur1-> first level node 8 8 level 1 node 8 1

3 parent node 1 murmurs-> first level node 8 murmurs-> secondary nodes 23 23 secondary nodes 23 8

-- Tree query 2: query all parent nodes of a node (that is, all previous generations)

SELECT * FROM YAG_TREE START WITH T_ID=26 CONNECT BY PRIOR PARENTID=T_ID

T_ID T_CONTEXT PARENTID

26 secondary nodes 26 11

11 Node 1 11 2

2 parent Node 2

Learning Resources: http://www.cnblogs.com/linjiqin/archive/2013/06/24/3152674.html

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report