Use this SQL statement
select * from tree
View the raw data as follows:
The following figure shows the result of a tree query (including the fields root, level, is_leaf, and Path ):
Execute the following SQL statement:
select connect_by_root(child_col) root, level , decode(connect_by_isleaf,0,'No',1,'Yes') is_leaf, sys_connect_by_path(child_col,'/') pathfrom treestart with parent_col is null connect by prior child_col=parent_col;
The focus of tree query is the start with... connect by prior... statement.
And connect_by_root, connect_by_isleaf, and sys_connect_by_path functions. Decode is a common function.
Other references: http://www.cnblogs.com/tongzhenhua/archive/2008/09/23/1297253.html
Example of a dynamic query statement:
declare n_rows number; v_sql_stmt varchar2(50); v_table_name varchar2(20); v_name varchar2(20);begin v_table_name := 'tree'; v_sql_stmt := 'select count(*) from ' || v_table_name || ' where parent_col = :1'; v_name := 'asia'; dbms_output.put_line(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;