2014-04-03 55 views
2

我對一個視圖運行此XML查詢創建的XMLType XML一個看法?即使用和XMLSequence(光標)

select xmlelement("clientid", xmlattributes (a.clientid), 
           (select xmlagg(
               xmlelement("plan", 
               xmlattributes(b.planid,b.planame), 
                xmlagg(xmlelement ("ppt", xmlattributes (b.pname, b.pdname) 
    )))) from **table(xmlsequence(cursor))** b 
      where b.clientid = a.clientid 
      group by b.planid,b.planname)) as xml from **table(xmlsequence(cursor))** a group by a.clientid; 

還是有另一種方法來做到這一點? 我的Oracle XML的東西實在是缺乏,所以我道歉,如果我的問題是福利局十歲上下... 感謝

回答

0

我不知道這是否是一個解決方案,但如果我想做出一個xml我正在doinig這樣的:

我聲明光標:

CURSOR cur(l_date_od date, l_date_do date) IS 
    select ... from .. where ...; 

我聲明光標行類型

variable cur%ROWTYPE; 

並選擇到每個可變XML_TYPE行

open cur(local_date1,local_date2); 
    loop 
    fetch linia into variable ; 
    exit when cur%NOTFOUND; 
    select xmlelement("ROW", 
      xmlelement("VENDOR_SITE_CODE",variable .VENDOR_SITE_CODE), 
      xmlelement("ATTRIBUTE1",variable .ATTRIBUTE1), 
      xmlelement("INVOICE_NUM",variable .INVOICE_NUM), 
      xmlelement("INVOICE_DATE",variable .INVOICE_DATE) 
      ) 
     into xml_type_variable 
     FROM dual; 
     xml_file2 :=(xml_file.getClobVal()); ----Here i am conversing to clob 
    end loop; 
    close linia;