Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

XML(XMLTYPE) and date format

Gert PoelJul 13 2012 — edited Jul 16 2012
Hi all,

I try to generate some XML in PL/SQL.
select xmlelement("Date", sysdate).getClobVal() from dual;

XMLELEMENT("DATE",SYSDATE).GETCLOBVAL()
-------------------------------------------
<Date>2012-07-13</Date>
This is the date format I expected(standard XML date format).

And the Oracle Documentation describes it:
"The XML Schema standard specifies that dates and timestamps in XML data be in standard formats. XML generation functions in Oracle XML DB produce XML dates and timestamps according to this standard."


When I want to create some XML from a query, I tried this
DECLARE

   l_refcursor SYS_REFCURSOR;
   l_xmltype xmltype;
   l_ctx dbms_xmlgen.ctxHandle;
     
BEGIN

   OPEN l_refcursor FOR select sysdate "Date" from dual;

   l_ctx := dbms_xmlgen.newContext (l_refcursor);
   dbms_xmlgen.setRowTag (l_ctx, null);
   dbms_xmlgen.setRowSetTag (l_ctx, null);
   l_xmltype := dbms_xmlgen.getXMLType (l_ctx);
   dbms_xmlgen.closeContext (l_ctx);
   
   dbms_output.put_line(l_xmltype.getClobVal());
END;
/

<Date>13-JUL-12</Date>
I expected also the XML standard date format, but I get the nls_date_format.

Of course I can use to_char and specify the correct date format or do an alter session(alter session set nls_date_format='RRRR-MM-DD'; ), but I wonder why XMLElement uses the standard and dbms_xmlgen not.
Or is there another way to use the default XML standard?

Gert
This post has been answered by MichaelS on Jul 13 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 13 2012
Added on Jul 13 2012
6 comments
4,767 views