Writing a correspondence between Oracle and XSD data types

时间:2015-05-12 22:14:35

标签: xml oracle xsd

My task is to create a conversion from Oracle metadata to XSD formatting to ensure correct translation of data from Oracle to XML.

To accomplish this I need to provide a correspondence table for the Oracle data types and XSD data types. The following is such a table for numbers. Right part of the expression is Oracle's Number datatype format, and the left one are the tags to be inserted into the "restriction" element of xs:decimal tag in XSD. Then the explanation goes.

Number(null,null) <-> totalDigits=38 : any 38 digits with/without decimal point

Number(4,2) <-> totalDigits=4; fractionDigits=2 : any 4 digits with decimal point from a missing one to the one in the middle of 4 digits; but what about "1600" ? it matches XSD, but not sure its ok for Oracle's Number(4,2)

Number(4,0) <-> totalDigits=4;fractionDigits=0 : integer with 4 digits

(1) Is my understanding correct? Could you provide me with a better match between Oracle and XSD numeric data types?

(2) Is there a built-in way to generate XSD from Oracle table?

1 个答案:

答案 0 :(得分:0)

这个限制并不是一个好主意。数字类型定义为NUMBER(精度,比例),请参阅http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements001.htm中表2-2中的示例 您必须为限制生成正则表达式模式,例如:

NUMBER(4)"-?[0-9]{1,4}"
NUMBER(4,2)"-?([0-9]{1,2})?(\.[0-9]{1,2})?"
NUMBER(4,-2)"0|-?[0-9]{1,4}0{2}"
NUMBER(2,-4)"0|-?[0-9]{1,2}0{4}"
NUMBER(2,4)"0|-?0?\.0{2}[0-9]{1,2}"

对于具有正比例的NUMBER类型,您可以使用totalDigits,fractionDigits,minExclusive和maxExclusive的组合。

NUMBER(4)totalDigits="4" fractionDigits="0"
NUMBER(4,2)totalDigits="4" fractionDigits="2" minExclusive="-100" maxExclusive="100"
NUMBER(2,4)totalDigits="4" fractionDigits="4" minExclusive="-.01" maxExclusive=".01"