Oracle tree SQL query instance analysis using this SQL statement [SQL] select * from tree to view the original data is as follows:
We want to obtain the following tree query result, as shown in
(Contains four fields: ROOT, LEVEL, IS_LEAF, and PATH ):
Run the following SQL statement: [SQL] select connect_by_root (child_col) root, level,
Decode (connect_by_isleaf, 0, 'No', 1, 'yes') is_leaf, sys_connect_by_path (child_col ,'/') path from tree www.2cto.com start with parent_col is null connect by prior child_col = parent_col; [SQL] tree query focuses on start... connect by prior .... statement [SQL] And connect_by_root, connect_by_isleaf, sys_connect_by_path,
Decode is a common function. Other references: http://www.bkjia.com/database/201205/131485.html dynamic query statement example: [SQL] declare n_rows number; v_ SQL _stmt varchar2 (50); v_table_name varchar2 (20); v_name varchar2 (20); begin www.2cto.com v_table_name: = 'tree'; v_ SQL _stmt: = 'select count (*) from' | v_table_name | 'where parent_col =: 1'; v_name: = 'asa '; explain (v_ SQL _stmt); execute immediate v_ SQL _stmt into n_rows using v_name; dbms_output.put_line ('the number of rows of '| v_table_name |' is '| n_rows); end;
From the blue temptation Column