Use of Oracle Contact By, oraclecontact

Source: Internet
Author: User

Use of Oracle Contact By, oraclecontact
1. Overview

Oracle "connect by" is a hierarchical query clause, which is generally used for query of tree or hierarchical result sets.

 

2. usage method 2. 1. Use Connect by to generate a sequence
Oracle constructs the number of days of a month select to_date ('20170101', 'yyymmm') + (rownum-1) s_date from dual connect by rownum <= last_day (to_date ('20170101 ', 'yyyymm')-to_date ('20140901', 'yyyymm') + 1

Generate a sequence FROM 1 to 10 select rownum from dual connect by rownum <= 10

2.2 tree-like query results
Create table DEP (DEPID number (10) not null, DEPNAME varchar2 (256), UPPERDEPID number (10) values insert into dep (DEPID, DEPNAME, UPPERDEPID) VALUES (0, 'General authorization', null); insert into dep (DEPID, DEPNAME, UPPERDEPID) VALUES (1, 'Demo', 0); insert into dep (DEPID, DEPNAME, UPPERDEPID) VALUES (2, 'test part', 0); insert into dep (DEPID, DEPNAME, UPPERDEPID) VALUES (3, 'sever demo', 1); insert into dep (DEPID, DEPNAME, UPPERDEPID) VALUES (4, 'client demo', 1); insert into dep (DEPID, DEPNAME, UPPERDEPID) VALUES (5, 'ta testing part', 2 ); insert into dep (DEPID, DEPNAME, UPPERDEPID) VALUES (6, 'Project test part', 2); explain select rpad ('', 2*(LEVEL-1 ), '-') | DEPNAME "DEPNAME", CONNECT_BY_ROOT DEPNAME "ROOT", CONNECT_BY_ISLEAF "ISLEAF", LEVEL, SYS_CONNECT_BY_PATH (DEPNAME ,'/') "PATH" from depstart with upperdepid is nullconnect by prior depid = UPPERDEPID;

Download DEMO

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.