Repeating nodes using FOR loop but when concating XML string then concating only last iteration of FOr loop ??

I stuck with a problem that I am using FOR loop for generating repeating nodes. 
Now when I concat the generated node in the main node then I got only last iteration of that FOR loop.
can anybody suggest me a way to handle this error....
FOR i IN 1..pl_phone_tab.Count
LOOP
SELECT xmlelement("Phone"     
                                    ,xmlelement("PHONETYPE",xmlattributes('01' AS "dmnADRP_PHONETYPE"),pl_phone_tab(i).p_phtype_tab)
                     ,xmlelement("PHONENUM",pl_phone_tab(i).p_phnum_tab)
                     ,xmlelement("PRIMARY_CONTACT",pl_phone_tab(i).p_prcon_tab)
INTO p_phone_xml
FROM dual; END LOOP;
SELECT xmlelement("PhoneInfo"
                       ,xmlconcat(p_phone_xml))
INTO p_phone_info_xml
FROM dual;
here I am getting only one node but there has to be two nodes for PHONE node

Not that I'm encouraging you but here are two standalone examples explaining how to do what you want :
1) Loop through the input collection and append each node to its target container :
SQL> declare
  2 
  3    type t_emp_tab is table of scott.emp%rowtype;
  4 
  5    emp_tab       t_emp_tab;
  6    emp_info_xml  xmltype;
  7    emp_xml       xmltype;
  8 
  9  begin
10 
11    -- filling emp_tab with data
12    select e.*
13    bulk collect into emp_tab
14    from scott.emp e
15    where e.deptno = 10;
16 
17    emp_info_xml := xmltype('<EmpInfo/>');
18 
19    -- looping through emp collection and appending to EmpInfo element
20    for i in 1 .. emp_tab.count loop
21      select appendchildxml(
22               emp_info_xml
23             , '/*'
24             , xmlelement("Emp"
25               , xmlattributes(emp_tab(i).empno as "id")
26               , xmlforest(
27                   emp_tab(i).ename as "Name"
28                 , emp_tab(i).job as "Job"
29                 )
30               )
31             )
32      into emp_info_xml
33      from dual;
34    end loop;
35 
36    dbms_output.put_line(emp_info_xml.getclobval(1,2));
37 
38  end;
39  /
<EmpInfo>
  <Emp id="7782">
    <Name>CLARK</Name>
    <Job>MANAGER</Job>
  </Emp>
  <Emp id="7839">
    <Name>KING</Name>
    <Job>PRESIDENT</Job>
  </Emp>
  <Emp id="7934">
    <Name>MILLER</Name>
    <Job>CLERK</Job>
  </Emp>
</EmpInfo>
PL/SQL procedure successfully completed
2) Build a secondary collection of XML nodes and use XMLAgg to aggregate them in one go :
SQL> declare
  2 
  3    type t_emp_tab is table of scott.emp%rowtype;
  4 
  5    emp_tab       t_emp_tab;
  6    emp_info_xml  xmltype;
  7    emp_xml_tab   xmlsequencetype := xmlsequencetype();
  8 
  9  begin
10 
11    -- filling emp_tab with data
12    select e.*
13    bulk collect into emp_tab
14    from scott.emp e
15    where e.deptno = 10;
16 
17    -- looping through emp collection and appending to the collection of Emp nodes
18    for i in 1 .. emp_tab.count loop
19 
20      emp_xml_tab.extend;
21 
22      select xmlelement("Emp"
23             , xmlattributes(emp_tab(i).empno as "id")
24             , xmlforest(
25                 emp_tab(i).ename as "Name"
26               , emp_tab(i).job as "Job"
27               )
28             )
29      into emp_xml_tab(i)
30      from dual;
31 
32    end loop;
33 
34    select xmlelement("EmpInfo", xmlagg(t.column_value))
35    into emp_info_xml
36    from table(emp_xml_tab) t ;
37 
38    dbms_output.put_line(emp_info_xml.getclobval(1,2));
39 
40  end;
41  /
<EmpInfo>
  <Emp id="7782">
    <Name>CLARK</Name>
    <Job>MANAGER</Job>
  </Emp>
  <Emp id="7839">
    <Name>KING</Name>
    <Job>PRESIDENT</Job>
  </Emp>
  <Emp id="7934">
    <Name>MILLER</Name>
    <Job>CLERK</Job>
  </Emp>
</EmpInfo>
PL/SQL procedure successfully completed
Both solutions give the same output.
Test them both and see which one fits better into your scenario.

Similar Messages

Maybe you are looking for

  • Skillbuilders modal page plugin query

    Hi Guys, I have downloaded the Skillbuilders modal page plugin and it works very well for 99% of the scenarios that we have encountered. We have one page which needs a slight modification from the standard functionality with regards the modal plug in

  • Is there a deus ex maquina for the hashed over HDV- DV conversion issues in the temples of FCP and Compressor??

    I want to create a good quality SD DVD  from 1080i/60 footage (20 minutes duration) from a Sony ZiU camera (mini DV tape) using FCP and Compressor. I can't do it. My hair has fallen out, but I don't want to throw in the towel. I have imported the sam

  • Um, slight problem with 6.0.2...

    ... as in, it has rendered my iPhoto useless. I cannot edit any photos - I just get white screen, and full screen mode causes the program to hang indefinitely. The probelm occurs with all of my 4,000-odd photos. Old ones, not so old ones, and even ph

  • Can not getReadMethod a jdk 1.5 bug?

    import junit.framework.TestCase; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import org.apache.taglibs.standard.lang.jstl.BeanInfoManager; import org.apache.taglibs.standard.lang.jstl.

  • Problem for import dmp file

    Hi, I had installed both oracle 8i and 11g, I'm trying to import my dmp file in oracle 8i, but that query will shift to 11g environment. How can i import my dmp file in 8i. eg: host imp sys/sys@ora file='D:\Ven_Excercise\hlw_demo\koow.dmp' ignore=y f