Use this SQL statement
- Select*FromTree
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:
- SelectConnect_by_root (child_col) root,Level, Decode (connect_by_isleaf, 0,'No', 1,'Yes') Is_leaf, sys_connect_by_path (child_col,'/') Path
- FromTree
- StartWithParent_colIs Null Connect By PriorChild_col = parent_col;
Tree query focuses on startWith...Connect By Prior... Statement
And connect_by_root, connect_by_isleaf, and sys_connect_by_path functions. decode is a common function.
Other references:
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: ='Air';
- Dbms_output.put_line (v_ SQL _stmt );
- ExecuteImmediate v_ SQL _stmtIntoN_rows using v_name;
- Dbms_output.put_line ('The number of rows'| V_table_name |'Is'| N_rows );
- End;
For more information about Oracle, see Oracle topics page http://www.bkjia.com/topicnews.aspx? Tid = 12