Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
On this page

Show all

CONNECT BY

Updated on 2022-08-16 GMT+08:00

Input-CONNECT BY

select id from city_branch start with id=roleBranchId connect by prior id=parent_id;
SELECT T.BRANCH_LEVEL, t.ID
                    FROM city_branch c
                   WHERE     (c.branch_level = '1' OR T.BRANCH_LEVEL = '2')
                         AND (T.SIGN = '1' OR T.SIGN = '4' OR T.SIGN = '8')
                         AND T.STATUS = '1'
              START WITH c.ID = I_BRANCH_ID
              CONNECT BY c.ID = PRIOR c.parent_id
                ORDER BY c.branch_level DESC ; 

Output

WITH RECURSIVE migora_cte AS (
     SELECT
               id
               ,1 AS LEVEL
          FROM
               city_branch
          WHERE
               id = roleBranchId
     UNION
     ALL SELECT
             mig_ora_cte_join_alias.id
             ,mig_ora_cte_tab_alias.LEVEL + 1 AS LEVEL
          FROM
             migora_cte mig_ora_cte_tab_alias INNER JOIN city_branch mig_ora_cte_join_alias
                 ON mig_ora_cte_tab_alias.id = mig_ora_cte_join_alias.parent_id
) SELECT
          id
     FROM
          migora_cte
     ORDER BY
          LEVEL
;
 
WITH RECURSIVE migora_cte AS (
     SELECT
               BRANCH_LEVEL
               ,ID
               ,SIGN
               ,STATUS
               ,parent_id
               ,1 AS LEVEL
          FROM
               city_branch c
          WHERE
               c.ID = I_BRANCH_ID
     UNION
     ALL SELECT
               c.BRANCH_LEVEL
               ,c.ID
               ,c.SIGN
               ,c.STATUS
               ,c.parent_id
               ,mig_ora_cte_tab_alias.LEVEL + 1 AS LEVEL
          FROM
               migora_cte mig_ora_cte_tab_alias INNER JOIN city_branch c
                    ON c.ID = mig_ora_cte_tab_alias.parent_id
) SELECT
          BRANCH_LEVEL
          ,ID
     FROM
          migora_cte c
     WHERE
          (
               c.branch_level = '1'
               OR T.BRANCH_LEVEL = '2'
          )
          AND( T.SIGN = '1' OR T.SIGN = '4' OR T.SIGN = '8' )
          AND T.STATUS = '1'
     ORDER BY
          c.branch_level DESC
;

Input - CONNECT BY multiple tables

The syntax shows the relationship between each child row and its parent row. It uses the CONNECT BY xxx PRIOR clause to define the relationship between the current row (child row) and the previous row (parent row).

SELECT DISTINCT a.id menuId,
               F.name menuName,
               a.status menuState,
               a.parent_id menuParentId,
               '-1' menuPrivilege,
               a.serialNo menuSerialNo
  FROM CTP_MENU a, CTP_MENU_NLS F
  START WITH a.serialno in (1, 2, 3)
CONNECT BY a.id = PRIOR a.parent_id
       AND f.locale = Language
       AND a.id = f.id
ORDER BY menuId, menuParentId;

Output

WITH RECURSIVE migora_cte AS (
        SELECT pr.service_product_id
             , t.enabled_flag
             , pr.operation_id
             , pr.enabled_flag
             , pr.product_code
             , 1 AS LEVEL
          FROM asms.cppsv_operation_sort t
             , asms.cppsv_product_class pr
         WHERE level_id = 3
           AND pr.operation_id = t.operation_id(+)
      UNION ALL 
         SELECT pr.service_product_id
              , t.enabled_flag
              , pr.operation_id
              , pr.enabled_flag
              , pr.product_code
              , mig_ora_cte_tab_alias.LEVEL + 1 AS LEVEL
           FROM migora_cte mig_ora_cte_tab_alias
              , asms.cppsv_operation_sort t
              , asms.cppsv_product_class pr
          WHERE mig_ora_cte_tab_alias.service_product_id = pr.service_product_father_id
            AND pr.operation_id = t.operation_id(+) ) 
SELECT pr.service_product_id
  FROM migora_cte
 WHERE nvl( UPPER( enabled_flag ) ,'Y' ) = 'Y'
   AND nvl( enabled_flag ,'Y' ) = 'Y'
   AND pr.product_code = rec_product1.service_product_code
 ORDER BY LEVEL;

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback