1. 程式人生 > >Oracle樹形查詢,路徑,有條件判斷

Oracle樹形查詢,路徑,有條件判斷

select *
  from (select distinct t.cid id,
                        t.pid pid,
                        t.corder,
                        t.code_name name,
                        LEVEL lv,
                        connect_by_isleaf isleaf,
                        t.code_enabled,
                        ltrim(sys_connect_by_path(CODE_NAME, '.'), '.') paths,
                        decode(Level,
                               5,
                               decode(t.code_enabled,
                                      1,
                                      decode(connect_by_isleaf, 1, 'icon-ok'))) iconcls
          from c_code_bxxmlx t
         where t.code_year = '2018'
         start with t.pid = 'root'
        connect by prior t.cid = t.pid) tb
 order by tb.corder