We have a standard oracle package to generate the XML Tags.
We just need to pass the SQL statement as parameter to the package.
Below is an example, which prints Todays date as XML Tag
SELECT DBMS_XMLGEN.getxml ('select sysdate today_date from dual') xml
FROM DUAL;
*****************************************************************
There is another way to get the same output using some other functions.
Let me start off with a simple query to print TODAY_DATE tag only
SELECT XMLELEMENT ("TODAY_DATE", SYSDATE) FROM DUAL;
Below is the output for the above statement
2011-11-21
Now, Let me change the date format as DD-MON-YY
SELECT XMLELEMENT ("TODAY_DATE", TO_CHAR (SYSDATE, 'DD-MON-YY'))
FROM DUAL;
Below is the output for the above statement
21-NOV-11
Now, i will modify the query to get same output as we got using standard package
SELECT ''
|| XMLELEMENT (
"ROWSET",
XMLELEMENT (
"ROW",
XMLELEMENT ("TODAY_DATE", TO_CHAR (SYSDATE, 'DD-MON-YY'))
)
)
FROM DUAL;
Below is the output for the above statement, which is same as what we got using standard package
|
21-NOV-11
We just need to pass the SQL statement as parameter to the package.
Below is an example, which prints Todays date as XML Tag
SELECT DBMS_XMLGEN.getxml ('select sysdate today_date from dual') xml
FROM DUAL;
*****************************************************************
There is another way to get the same output using some other functions.
Let me start off with a simple query to print TODAY_DATE tag only
SELECT XMLELEMENT ("TODAY_DATE", SYSDATE) FROM DUAL;
Below is the output for the above statement
Now, Let me change the date format as DD-MON-YY
SELECT XMLELEMENT ("TODAY_DATE", TO_CHAR (SYSDATE, 'DD-MON-YY'))
FROM DUAL;
Below is the output for the above statement
Now, i will modify the query to get same output as we got using standard package
SELECT ''
|| XMLELEMENT (
"ROWSET",
XMLELEMENT (
"ROW",
XMLELEMENT ("TODAY_DATE", TO_CHAR (SYSDATE, 'DD-MON-YY'))
)
)
FROM DUAL;
Below is the output for the above statement, which is same as what we got using standard package
*****************************************************************************
Ur's
AmarAlam
0 comments:
Post a Comment