We have a table with a parent-child relation and would like to get it sorted. The sorting criteria is so that when iterating though the result the row matching a parent ID should already be there :
ID PARENT_ID
EF01 EF02 // This is wrong as the row EF02 is after and will fail.
EF02
BB AA // here BB < AA
AA EF01
The problem is that both key are string, therefore sorting by ID or PARENT_ID is not going to fix the problem.
解决方案select id, parent_id, level from the_table
start with parent_id is null
connect by prior id = parent_id;