sql - A connect by query on all children -
is there way have connect prior... start with
statement in oracle start first "child" in table , run query remaining children well? know how use statement 1 child , ancestry, need code run lots of different children in table.
let's suppose have code returns component , component's color table of components , component's parent , classified "sample" , color component's parent id id of parent component.
this schema:
components table: component component_id component_parent_id component_label component_color table: component component_color
note: example code, not 1 using, if silly errors, sorry.
select component, components inner join component_color on (components.component = component_color.component) component_label = 'sample' connect prior component_header.component_parent_id = component_header.component_id start component.component_id = '2000';
table component has lot of different components , want query return not component id 2000 , "sample" parent, children in table "components".
i can see how can done loop, cannot find type of loop can use oracle. sorry, starting.
avoid using where
, order by
clauses in hierachical queries, because run after hierarchical processing. here think should use start component_label = 'sample'
.
select level, components.component_id, components.component_label, component_color.component_color compenents join component_color on components.component = component_color.component start components.component_label = 'sample' connect prior components.component_id = components.component_parent_id
Comments
Post a Comment