从自引用 Oracle 表生成 XML
我有一个 Oracle 数据库,其中有一个名为“服务”的分层医疗数据的自引用表。
服务
service_id ---------- 号码
服务名称 ----- varchar2(200)
service_parent --- number
,其中每个服务可以有 1 个父服务以及 n 个子服务。 “顶级”服务的 service_parent 值为零。
我需要根据这些数据生成 XML 结构。我在网上搜索过,但似乎找不到此类 XML 生成的示例。 这是我需要的 XML 输出的示例:
<services>
<service id="1" name="Medicine">
<service id="10" name="Anesthesia">
</service>
</service>
<service id="2" name="Surgery">
<service id="3" name="Cardiology">
<service id="4" name="Bypass">
</service>
<service id="5" name="Transplant">
</service>
<service id="6" name="Valve Replacement">
</service>
</service>
<service id="9" name="Ear Nose Throat">
<service id="7" name="Laryngectomy">
</service>
<service id="8" name="Septoplasty">
</service>
</service>
</service>
</services>
我尝试过使用 CONNECT_BY_ISLEAF、CONNECT_BY_PATH、CONNECT BY PRIOR 等...但我能得到的最接近的是:
<services>
<service id="1" name="Medicine" />
<service id="10" name="Anesthesia" />
<service id="2" name="Surgery" />
<service id="3" name="Cardiology" />
<service id="4" name="Bypass" />
<service id="5" name="Transplant" />
<service id="6" name="Valve Replacement" />
<service id="9" name="Ear Nose Throat" />
<service id="8" name="Laryngectomy" />
<service id="7" name="Septoplasty" />
</services>
获取上面 XML 结构的最佳方法是什么?
I have an Oracle DB with a self referencing table of hierarchical medical data called "services".
Services
service_id ---------- number
service_name ----- varchar2(200)
service_parent --- number
where each service can have 1 parent service as well as n number of children.
"Top level" services would have a service_parent value of zero.
I need to generate an XML structure from this data. I've scoured the web but cannot seem to find an example of this sort of XML generation.
This is an example of the XML output I need:
<services>
<service id="1" name="Medicine">
<service id="10" name="Anesthesia">
</service>
</service>
<service id="2" name="Surgery">
<service id="3" name="Cardiology">
<service id="4" name="Bypass">
</service>
<service id="5" name="Transplant">
</service>
<service id="6" name="Valve Replacement">
</service>
</service>
<service id="9" name="Ear Nose Throat">
<service id="7" name="Laryngectomy">
</service>
<service id="8" name="Septoplasty">
</service>
</service>
</service>
</services>
I've tried using CONNECT_BY_ISLEAF, CONNECT_BY_PATH, CONNECT BY PRIOR, etc... but the closest I could get it was:
<services>
<service id="1" name="Medicine" />
<service id="10" name="Anesthesia" />
<service id="2" name="Surgery" />
<service id="3" name="Cardiology" />
<service id="4" name="Bypass" />
<service id="5" name="Transplant" />
<service id="6" name="Valve Replacement" />
<service id="9" name="Ear Nose Throat" />
<service id="8" name="Laryngectomy" />
<service id="7" name="Septoplasty" />
</services>
What is the best way to get the XML structure above?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个使用
DBMS_XMLGEN.newContextFromHierarchy
的示例看起来与您尝试执行的操作非常相似。This example using
DBMS_XMLGEN.newContextFromHierarchy
looks pretty similar to what you're trying to do.