provide-free-support Ujjwal's Blog: xsd
Showing posts with label xsd. Show all posts
Showing posts with label xsd. Show all posts

Tuesday, July 3, 2012

Generate XSD of Oracle Tables

Hi,

Recently i was finding a way across generating XSD from Oracle Tables. I found a way as below which fulfills my requirement.

Create a plsql function in oracle as below, i used oracle 10G

create or replace function GENERATE_XSD(target_table varchar2) return xmltype
as
xmlSchema XMLTYPE;
begin
select
xmlElement(
"xsd:schema",
xmlAttributes(
'http://www.w3.org/2001/XMLSchema' as "xmlns:xsd",
'http://xmlns.oracle.com/xdb' as "xmlns:xdb"
),
xmlElement(
"xsd:element",
xmlAttributes(
'ROWSET' as "name",
'rowset' as "type"
)
),
xmlElement(
"xsd:complexType",
xmlAttributes
(
'rowset' as "name"
),
xmlElement
(
"xsd:sequence",
xmlElement
(
"xsd:element",
xmlAttributes
(
'ROW' as "name",
table_name || '_T' as "type",
'unbounded' as "maxOccurs"
)
)
)
),
xmlElement
(
"xsd:complexType",
xmlAttributes
(
table_name || '_T' as "name"
),
xmlElement
(
"xsd:sequence",
(
xmlAgg(ELEMENT)
)
)
)
)
into xmlSchema
from (
select TABLE_NAME, INTERNAL_COLUMN_ID,
case
when DATA_TYPE in ('VARCHAR2', 'CHAR') then
xmlElement
(
"xsd:element",
xmlattributes
(
column_name as "name",
decode(NULLABLE, 'Y', 0, 1) as "minOccurs",
column_name as "xdb:SQLName",
DATA_TYPE as "xdb:SQLTYPE"
),
xmlElement
(
"xsd:simpleType",
xmlElement
(
"xsd:restriction",
xmlAttributes
(
'xsd:string' as "base"
),
xmlElement
(
"xsd:maxLength",
xmlAttributes
(
DATA_LENGTH as "value"
)
)
)
)
)
when DATA_TYPE = 'DATE' then
xmlElement
(
"xsd:element",
xmlattributes
(
column_name as "name",
--'xsd:dateTime' as "type",
'xsd:date' as "type",
decode(NULLABLE, 'Y', 0, 1) as "minOccurs",
column_name as "xdb:SQLName",
DATA_TYPE as "xdb:SQLTYPE"
)
)
when DATA_TYPE = 'NUMBER' then
xmlElement
(
"xsd:element",
xmlattributes
(
column_name as "name",
decode(DATA_SCALE, 0, 'xsd:integer', 'xsd:double') as "type",
decode(NULLABLE, 'Y', 0, 1) as "minOccurs",
column_name as "xdb:SQLName",
DATA_TYPE as "xdb:SQLTYPE"
)
)
else
xmlElement
(
"xsd:element",
xmlattributes
(
column_name as "name",
'xsd:anySimpleType' as "type",
decode(NULLABLE, 'Y', 0, 1) as "minOccurs",
column_name as "xdb:SQLName",
DATA_TYPE as "xdb:SQLTYPE"
)
)
end ELEMENT
from user_tab_cols c
where TABLE_NAME = target_table
order by internal_column_id
)
group by TABLE_NAME;

return xmlSchema;
end;


Run it as below ::

select GENERATE_XSD('EMPLOYEE_SALARY_TABLE').extract('/*') from dual;

Dont forget to put '.extract('/*')' before from dual.



Cheers,

Ujjwal Soni
best-it-exam-    | for-our-work-    | hottst-on-sale-    | it-sale-    | tast-dumps-us-    | test-king-number-    | pass-do-it-    | just-do-it-    | pass-with-us-    | passresults-everything-    | passtutor-our-dumps-    | realtests-us-exam-    | latest-update-source-for-    | cbtnuggets-sale-exam    | experts-revised-exam    | certguide-sale-exam    | test4-sale-exam    | get-well-prepared-    | certkiller-sale-exam    | buy-discount-dumps    | how-to-get-prepared-for-the    | in-an-easy-way    | brain-dumps-sale    | with-pass-exam-guarantee    | accurate-study-material    | at-first-try    | 100%-successful-rate    | get-certification-easily    | material-provider-exam    | real-exam-practice    | with-pass-score-guarantee    | certification-material-provider    | for-certification-professionals    | get-your-certification-successfully    | 100%-Pass-Rate    | in-pdf-file    | practice-exam-for    | it-study-guides    | study-material-sku    | study-guide-pdf    | prep-guide-demo    | certification-material-id    | actual-tests-demo    | brain-demos-test    | best-pdf-download    | our-certification-material    | best-practice-test    | leading-provider-on    | this-course-is-about    | the-most-reliable    | high-pass-rate-of    | high-pass-rate-demo    | recenty-updated-key    | only-for-students-free-download    | courseware-plus-kit-for    | accurate-answers-of    | the-most-reliable-id    | provide-training-for    | welcome-to-buy    | material-for-success-pass    | provide-free-support    | best-book-for-pass    | accuracy-of-the-answers    | pass-guarantee-id    | pass-exam-key    | pass-sku-id    | study-for-exid    | pdf-sku-exid    | sku-pdf-id    | pdf-demo-key    | exam-demo-ske    | pass-it-dump    |
http://www.menuiserie-dauvergne.com/    | http://www.menuiserie-dauvergne.com/    |