XML IN THE DATABASE: THE XML DATA TYPE

XML IN THE DATABASE: THE XML DATA TYPE the character or National character data types, as well as BINARY and VARBINARY. When you cast from BINARY and VARBINARY, you can either specify the encoding in the XML itself or include the beginning byte-order mark (0xFFFE) if the format is Unicode. When you cast to BINARY or VARBINARY, the XML will be cast to UTF-16 with the byte-order mark present. You can cast a TEXT or NTEXT data type instance to an instance of the XML type, but you cannot cast an instance of the XML type to TEXT or NTEXT. Using one of the special methods of the XML data type (the value method, discussed later in this chapter) can produce different SQL data types. Listing 8-3 shows retrieving data from an XMLdata type column. Listing 8-3: Returning Data from an XML Data Type Column CREATE TABLE xml_tab( the_id INTEGER PRIMARY_KEY IDENTITY, xml_col XML) GO INSERT INTO xml_tab VALUES( ) INSERT INTO xml_tab VALUES(N ) GO both rows values are cast to the same data type SELECT CAST(xml_col as nchar(2000)) FROM xml_tab SELECT CONVERT(nchar(2000), xml_col) FROM xml_tab GO illegal SELECT CAST(xml_col as sql_variant) FROM xml_tab SELECT CONVERT(sql_variant, xml_col) FROM xml_tab GO Since the values of two XML data type instances cannot be compared (except using IS NULL), you cannot use the XML data type in SQL predicates or SQL clauses that require comparison, such as GROUP BYand ORDER BY. The XML data type also cannot be used in any scalar function or aggregate where comparison is required. However, because the XMLdata type is castable to any character-based type, this functionality will work if CAST (or CONVERT) is used. This behavior is exactly the behavior specified for a distinct data type by the SQL:1999 specification. Although comparison of the XML document type as a string is risky, notice that in the preceding example, both and are converted to the same lexical form, , when the CAST or CONVERT functions are used. The XMLdata type does retain Infoset fidelity but does not guarantee

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services

Bookmark the permalink.

Comments are closed.