Home > Ask the Oracle Experts > (Archive) App Dev: PL/SQL and XML Questions & Answers > Concatenating XML fragments
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Concatenating XML fragments

Lewis Cunningham EXPERT RESPONSE FROM: Lewis Cunningham

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site


Oracle tips, scripts, and expert advice
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


>
QUESTION POSED ON: 15 August 2005
Using XMLElement and XMLForest I have created several XML "strings." In a final XMLElement select statement with XMLForest I want to concat the earlier strings within the output of the final statement, e.g.

Select xmlelement("FIRST STRING", xmlforest(cl1 "COL1", col2 "COL2"))
  into xmlstring1
  from table1
  where col1 = test;

Then a number of similar statements to get a number of XML strings and a final statement

select xmlelement("FINAL STRING", 
            xmlforest (col5 "COL5", 
                       col6 "COL6"||xmlstring1||col7 "COL7"||xmlstring2))
  into finalstring
  where . . .

Can concat be used within XMLElement or XMLForest in this way?


>
EXPERT RESPONSE
That's a great question. If I understand correctly, what you are trying to do is combine two XML fragments into a single XML document.

I won't try to guess why you're doing this in separate SELECT statements, or why you would want to recombine using SQL instead of PL/SQL. But, here is a working example to do what I think you are trying to do.

DECLARE
  XMLSTRING1    xmlType;
  XMLSTRING2    xmlType;
  XMLSTRING3    xmlType;
BEGIN
  
  SELECT xmlElement("FIRST_STRING", xmlForest(ename "COL1", job "COL2"))
    INTO xmlString1
    FROM emp
    WHERE ROWNUM = 1;

  DBMS_OUTPUT.put_line( xmlString1.getStringVal() );
      
  SELECT xmlElement("SECOND_STRING", xmlForest(sal "COL1", mgr "COL2"))
    INTO xmlString2
    FROM emp
    WHERE ROWNUM = 1;

  DBMS_OUTPUT.put_line( xmlString2.getStringVal() );
     
  SELECT xmlElement( "THIRD_STRING", xmlString1, xmlString2 )
    INTO xmlString3
    FROM DUAL;    

  DBMS_OUTPUT.put_line( xmlString3.getStringVal() );

END;

The first and second SELECT staements gather two XML fragments and the third statement uses XMLElement to combine them. I used DBMS_OUTPUT to display the intermediate results.

Hope that helps.


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


RELATED CONTENT
(Archive) App Dev: PL/SQL and XML
Detect if a column is NUMBER or VARCHAR2 in PL/SQL
Loading data into Oracle
Log execution time for a procedure
Hiding objects in a schema
Query for five most recent dates
Connecting with Visual Basic
SQL ANSI standards and compliance
Developing a parser for recognizing HTML tags
Oracle and SOAP
Two schemas on a single database

Oracle XML, SOA, Web services
Oracle XML DB generates power for electrical agency
Oracle updates Microsoft developer tools
Oracle vs. SAP: The SOA factor
Oracle's content management software plan takes shape
Top five data management buzzwords
Oracle updates free Web development tool
Podcast: Oracle vs. SAP -- SOA and Web services security
Oracle open sources TopLink at EclipseCon
Oracle or SQL Server for developing social networking site?
Oracle Database 11g to feature XML enhancements

Oracle SQL
SQL to count values of a status code
Counting NULL columns
Detail rows for accounts that occur three times
Counting a row's NULL columns
Oracle's free SQL Developer adds database migration tool
Latest transaction if no recent prior transactions
Three ways SQL can count rows by type
SQL to select only certain times within a date range
Oracle SQL to test for numerics
Number of rows in multiple tables
Oracle SQL Research

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
DSML  (SearchOracle.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice

HomeNewsTopicsTipsAsk the ExpertsWebcastsWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2003 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts