DB2 recursive query, also known as tree query, is a very important query method in DB2 databases. The following describes the knowledge of DB2 recursive query for your reference.
Data Structure]
Process_id par_process_id fw_id
742482939 414358129 471
414358129 1707251033 470
1707251033 null 468
DB2 recursive query parent process_id]
With par (process_id, par_process_id)
(
Select process_id, par_process_id from docm_process_ts a where fw_id = '20140901' 1]
Union all
Select child. process_id, child. par_process_id from par, docm_process_ts child where par. par_process_id = child. process_id 2]
)
Select process_id, par_process_id from par where par. par_process_id is null 3]
1] This SQL statement is initialized and only executed once. The execution result is passed to table 2 as a seed]
2) recursively retrieve data from the virtual table par and the docm_process_ts table with conditions
3] This SQL statement is the final result to be queried.
Implementation of DB2 Paging
DB2 cursor and usage
How to manage DB2 tablespaces
DB2 database Permissions
Quick clearing of big data DB2 tables