Oracle
 sql >> डेटाबेस >  >> RDS >> Oracle

ओरेकल सीटीई में रिकर्सिव क्वेरी को दोबारा करने की कोशिश कर रहा है?

मैं फिर से लिखने की कोशिश करूंगा:

with MyCTE3 (WorkflowStepName, Depth, WorkflowId, WorkflowStepId, SubWorkflowBaseId, SubWorkflowId, Sequence, StepType, JoinColumn, DisplayOrder) as 
(
    SELECT wfs.WorkflowStepName
           ,1 as Depth
           , wfs.WorkflowId
           , wfs.WorkflowStepId
           , wfs.SubWorkflowBaseId
           , wfs.SubWorkflowId
           , wfs.Sequence
           , wfs.StepType
           , case 
                when wfs.SubWorkflowBaseId = '0000000000000000' then wfs.SubworkflowId
                --when wfs.SubWorkflowBaseId is null then wfs.SubworkflowId
                when wfs.SubWorkflowId = '0000000000000000' then wfs.SubWorkflowBaseId
                --when wfs.SubWorkflowId is null then wfs.SubWorkflowBaseId
             end as JoinColumn
          ,1 || '.' || CAST(wfs.Sequence AS VARCHAR(255))  AS DisplayOrder
      --, to_clob(wfs.WorkflowId) as ProcessedWorkflow
      FROM WorkflowStep2 wfs, Workflow2  wf 
     WHERE wfs.WorkflowId = '1100000000000000' 
     and wf.WorkflowId = wfs.WorkflowId

    union all
    SELECT wfs.WorkflowStepName
            ,  Depth+1
            , wfs.WorkflowId
            , wfs.WorkflowStepId
            , wfs.SubWorkflowBaseId
            , wfs.SubWorkflowId
            , wfs.Sequence
            , wfs.StepType
            , case 
                when wfs.SubWorkflowBaseId = '0000000000000000' then wfs.SubworkflowId
                --when wfs.SubWorkflowBaseId is null then wfs.SubworkflowId
                when wfs.SubWorkflowId = '0000000000000000' then wfs.SubWorkflowBaseId
                --when wfs.SubWorkflowId is null then wfs.SubWorkflowBaseId
                end as JoinColumn
        ,DisplayOrder || '.' || CAST(Depth+1 AS VARCHAR(255)) || CAST(wfs.Sequence AS VARCHAR(255))  as DisplayOrder
        --,to_clob(myCTE3.ProcessedWorkflow) || ',' || to_clob(wfs.WorkflowId) as ProcessedWorkflow
        FROM workflowbase2 wfb, workflowstep2 wfs, workflow2 wf, MyCTE3     
    where  myCTE3.JoinColumn is not null
    -- and (','+to_clob(myCTE3.ProcessedWorkflow) +',' not like '%,'+to_clob(wfs.WorkflowId)+',%')    
    -- and (dbms_lob.instr(myCTE3.ProcessedWorkflow,wfs.WorkflowId) = 0)  
        AND
        (    
            myCTE3.SubWorkflowBaseId <>  '0000000000000000' 
            and myCTE3.SubWorkflowBaseId is not null 
            and myCTE3.JoinColumn = wfb.WorkflowBaseId
            and wfb.RevOfRcdId    = wf.WorkflowId
            and wf.workflowid     = wfs.WorkflowId
        )   
), mcte2(WorkflowStepName, Depth, WorkflowId, WorkflowStepId, SubWorkflowBaseId, SubWorkflowId, Sequence, StepType, JoinColumn, DisplayOrder) AS (
  SELECT wfs.WorkflowStepName
           ,1 as Depth
           , wfs.WorkflowId
           , wfs.WorkflowStepId
           , wfs.SubWorkflowBaseId
           , wfs.SubWorkflowId
           , wfs.Sequence
           , wfs.StepType
           , case 
                when wfs.SubWorkflowBaseId = '0000000000000000' then wfs.SubworkflowId
                --when wfs.SubWorkflowBaseId is null then wfs.SubworkflowId
                when wfs.SubWorkflowId = '0000000000000000' then wfs.SubWorkflowBaseId
                --when wfs.SubWorkflowId is null then wfs.SubWorkflowBaseId
             end as JoinColumn
          ,1 || '.' || CAST(wfs.Sequence AS VARCHAR(255))  AS DisplayOrder
      --, to_clob(wfs.WorkflowId) as ProcessedWorkflow
      FROM WorkflowStep2 wfs, Workflow2  wf 
     WHERE wfs.WorkflowId = '1100000000000000' 
     and wf.WorkflowId = wfs.WorkflowId

    union all


  SELECT wfs.WorkflowStepName
            ,  Depth+1
            , wfs.WorkflowId
            , wfs.WorkflowStepId
            , wfs.SubWorkflowBaseId
            , wfs.SubWorkflowId
            , wfs.Sequence
            , wfs.StepType
            , case 
                when wfs.SubWorkflowBaseId = '0000000000000000' then wfs.SubworkflowId
                --when wfs.SubWorkflowBaseId is null then wfs.SubworkflowId
                when wfs.SubWorkflowId = '0000000000000000' then wfs.SubWorkflowBaseId
                --when wfs.SubWorkflowId is null then wfs.SubWorkflowBaseId
                end as JoinColumn
        ,DisplayOrder || '.' || CAST(Depth+1 AS VARCHAR(255)) || CAST(wfs.Sequence AS VARCHAR(255))  as DisplayOrder
        --,to_clob(myCTE3.ProcessedWorkflow) || ',' || to_clob(wfs.WorkflowId) as ProcessedWorkflow
        FROM workflowbase2 wfb, workflowstep2 wfs, workflow2 wf, MyCTE3     
    where  myCTE3.JoinColumn is not null
       AND
        (
            myCTE3.SubWorkflowId <>  '0000000000000000'
            and myCTE3.SubWorkflowId is not null 
            and myCTE3.JoinColumn =  wf.workflowid 
            --and wf.workflowid     = wfs.SubWorkflowId
            and wf.workflowid     = wfs.WorkflowId
      and wf.WorkflowBaseId = wfb.WorkflowBaseId     
        ) 
)
select   WorkFlowStepName, DisplayOrder --, DisplayOrder, ProcessedWorkflow
  from MyCTE3
where MYCTE3.StepType <> 2
UNION ALL
select   WorkFlowStepName, DisplayOrder --, DisplayOrder, ProcessedWorkflow
  from MyCTE3
where MYCTE3.StepType <> 2
order by DisplayOrder ;

SQLFiddle डेमो

मैंने या विस्तार का उपयोग किया है




  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. संबंधपरक डेटाबेस में लिंक्ड सूची की प्रविष्टियां प्राप्त करना

  2. एसक्यूएल जॉइनिंग प्रश्न

  3. कर्सर अप्रचलन डंप

  4. ora-12154 हल नहीं कर सका... oracle तत्काल क्लाइंट के साथ

  5. Oracle (11.2.0.1):उस पंक्ति की पहचान कैसे करें जो वर्तमान में अद्यतन विवरण द्वारा अद्यतन की गई है