Comments on: Creating an XMLType based on Object Types https://technology.amis.nl/2010/12/23/creating-an-xmltype-based-on-object-types/ Friends of Oracle and Java Wed, 24 Jun 2015 09:59:44 +0000 hourly 1 http://wordpress.org/?v=4.2.2 By: tokke https://technology.amis.nl/2010/12/23/creating-an-xmltype-based-on-object-types/#comment-6431 Wed, 08 Feb 2012 15:13:02 +0000 http://technology.amis.nl/blog/?p=9473#comment-6431 alex, great blog, as usual. thanks. one question remains. i can’t appreciate the last definition of the type called all_departments_ot.
in the query without the xmltype you don’t use it. in the one that includes the xmltype you do. can you explain that difference, and the need for the use of the all_departments_ot?
much obliged,
 
-t-

]]>
By: Marco Gralike https://technology.amis.nl/2010/12/23/creating-an-xmltype-based-on-object-types/#comment-6430 Thu, 23 Dec 2010 18:59:19 +0000 http://technology.amis.nl/blog/?p=9473#comment-6430 Oh, I agree, just pointed out that in this case it might also be solved via a simple select within XMLTYPE(CURSOR())

]]>
By: Alex Nuijten https://technology.amis.nl/2010/12/23/creating-an-xmltype-based-on-object-types/#comment-6429 Thu, 23 Dec 2010 15:43:30 +0000 http://technology.amis.nl/blog/?p=9473#comment-6429 @Marco,

Personally I find the Object Types (with the CASTs and COLLECTs) a lot easier to read (and write) than using XMLType (with all the XMLElement, XMLAgg and so on).

Thank you for your comment.

]]>
By: Marco Gralike https://technology.amis.nl/2010/12/23/creating-an-xmltype-based-on-object-types/#comment-6428 Thu, 23 Dec 2010 15:19:02 +0000 http://technology.amis.nl/blog/?p=9473#comment-6428 The problem with object types is that complex nested structures will have very fast the same issue as your first XML/SQL example.

Based on your needs the easiest way to achieve this would be to use your query as input for XMLTYPE which can handle CURSOR constructs to for example:

select XMLTYPE(CURSOR( select d.department_name, d.manager_id, e.first_name, e.last_name, e.manager_id from departments d join employees   e on d.department_id = e.department_id where d.department_id = 20)) FROM DUAL;

Be aware that the “pretty print” format is not needed and creates overhead for the XML parser. Use XMLSerialize to bring it back to one big string without all the CR/LF and whitespace, if needed (this is the default in Oracle 11g and onwards)

 

]]>