光标循环;如何仅在循环开始/结束时执行某项操作 1 次?
我的 Oracle 程序之一中有以下内容,我使用它来生成 XML
-- v_client_addons is set to '' to avoid null error
OPEN C_CLIENT_ADDONS;
LOOP
FETCH C_CLIENT_ADDONS INTO CLIENT_ADDONS;
EXIT WHEN C_CLIENT_ADDONS%NOTFOUND;
BEGIN
v_client_addons := v_client_addons || CLIENT_ADDONS.XML_DATA;
END;
END LOOP;
CLOSE C_CLIENT_ADDONS;
-- Do something later with v_client_addons
循环应该遍历我的光标并挑选出所有要显示的 XML 值,例如:
<add-on name="some addon"/>
<add-on name="another addon"/>
我想要实现的是此循环内有一个 XML 开始/结束标记,因此我将得到以下输出
<addons>
<add-on name="some addon"/>
<add-on name="another addon"/>
</addons>
如何在每行后面不使用
标记的情况下执行此操作?如果光标中没有插件(光标为空),那么我想完全跳过这部分
I've got the following in one of my Oracle procedures, I'm using it to generate XML
-- v_client_addons is set to '' to avoid null error
OPEN C_CLIENT_ADDONS;
LOOP
FETCH C_CLIENT_ADDONS INTO CLIENT_ADDONS;
EXIT WHEN C_CLIENT_ADDONS%NOTFOUND;
BEGIN
v_client_addons := v_client_addons || CLIENT_ADDONS.XML_DATA;
END;
END LOOP;
CLOSE C_CLIENT_ADDONS;
-- Do something later with v_client_addons
The loop should go through my cursor and pick out all of the XML values to display, such as :
<add-on name="some addon"/>
<add-on name="another addon"/>
What I would like to achieve is to have an XML start/end tag inside this loop, so I would have the following output
<addons>
<add-on name="some addon"/>
<add-on name="another addon"/>
</addons>
How can I do this without having the <addons>
tag after every line? If there are no addons in the cursor (cursor is empty), then I would like to skip this part enitrely
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查 v_client_addons 的长度。如果它大于 0,则您实际上附加了一些内容。然后创建父标签及其子标签,否则忽略它。
check the length of v_client_addons. If it is greater than 0, you actually appened something. Then create you parent tag with its children, else just ignore it.
使用 SQL 生成整个 XML,而不是循环游标怎么样?
How about using SQL to generate the entire XML, instead of looping over a cursor?