Cursor loops; How to perform something at start/end of loop 1 time only?
Posted
by James.Elsey
on Stack Overflow
See other posts from Stack Overflow
or by James.Elsey
Published on 2010-04-12T10:44:00Z
Indexed on
2010/04/12
11:13 UTC
Read the original article
Hit count: 169
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
© Stack Overflow or respective owner