【发布时间】:2019-10-03 11:26:00
【问题描述】:
我想从 oracle 数据库中的表中提取层次结构。 表格如下所示:
+----+--------+----------------+---------------------+
| id | lvl1 | lvl2 | lvl3 |
+----+--------+----------------+---------------------+
| 1 | Oracle | Marketing unit | Internet |
+----+--------+----------------+---------------------+
| 2 | Oracle | Lawyers unit | Intellectual |
+----+--------+----------------+---------------------+
| 3 | Oracle | Finance unit | null |
+----+--------+----------------+---------------------+
| 4 | Oracle | Lawyers unit | Judicial department |
+----+--------+----------------+---------------------+
| 5 | Oracle | IT unit | Database |
+----+--------+----------------+---------------------+
| 6 | Oracle | Marketing unit | Television |
+----+--------+----------------+---------------------+
| 7 | Oracle | IT unit | ERP |
+----+--------+----------------+---------------------+
这就是我想要得到的:
- Oracle
. - Marketing unit
. - Internet
. - Television
. - Lawyers unit
. - Intellectual
. - Judicial department
. - Finance unit
. - IT unit
. - Database
. - ERP
我阅读了有关 Oracle 分层查询的信息,但我不知道如何使用我的表结构来实现它... 最后,我必须让 JSON 显示在网页上。 为了方便,我在sqlfiddle 上准备了一张桌子
感谢您的帮助, 有什么想法吗?
【问题讨论】:
标签: sql oracle hierarchy hierarchical-data