in the Oracle database I have a table which contains simple attributes such as:
name
first name
age
Goal: I would like to recover this data in XSD format.
are there SQL functions for that or java libraries that do that?
Thanks in advance
in the Oracle database I have a table which contains simple attributes such as:
name
first name
age
are there SQL functions for that or java libraries that do that?
Thanks in advance
XSD stands for XML Schema Definition and is used to describe an XML document's structure, constraints, data types. So you would put data in an XML document but the structure/format of that document (without any data) would be described by an associated XSD.
Since you are talking about data, you probably want an XML document (and not an XSD) and can use Oracle's XML functions:
Oracle Setup:
CREATE TABLE table_name ( first_name, last_name, date_of_birth ) AS
SELECT 'Alice', 'Adams', DATE '1970-01-01' FROM DUAL UNION ALL
SELECT 'Beryl', 'Booth', DATE '1980-01-01' FROM DUAL UNION ALL
SELECT 'Carol', 'Cross', DATE '1990-01-01' FROM DUAL;
Query:
SELECT XMLELEMENT(
"People",
XMLAGG(
XMLELEMENT(
"Person",
XMLFOREST(
first_name AS "FirstName",
last_name AS "LastName",
EXTRACT( YEAR FROM ( SYSDATE - date_of_birth ) YEAR TO MONTH ) AS "Age"
)
)
)
) AS XML
FROM table_name
Output:
| XML | | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | <People><Person><FirstName>Alice</FirstName><LastName>Adams</LastName><Age>50</Age></Person><Person><FirstName>Beryl</FirstName><LastName>Booth</LastName><Age>40</Age></Person><Person><FirstName>Carol</FirstName><LastName>Cross</LastName><Age>30</Age></Person></People> |
db<>fiddle here
If you really want to generate an XSD then you can do that using the same functions as an XSD is, itself, an XML document; but its not something you put data into.