Oracle9i XML API Reference - XDK and Oracle XML DB Release 2 (9.2) Part Number A96616-01 |
|
The DBMS_XMLGEN Package is used to transform results of SQL queries into a canonical XML format.
This chapter discusses the following topics:
DBMS_XMLGEN converts the results of a SQL query to a canonical XML format. The package takes an arbitrary SQL query as input, converts it to XML format, and returns the result as a CLOB.
This package is similar to the DBMS_XMLQUERY package, except that it is written in C and compiled into the kernel. This package can only be run in the database.
Generates and returns a new context handle; this context handle is used in getXML() and other functions to get XML back from the result. The available options are given in the following table.
Syntax | Description |
---|---|
RETURN ctxHandle; |
Generates a new context handle from a query. |
RETURN ctxHandle; |
Generates a new context handle from a query string in the form of a PL/SQL ref cursor |
Sets the name of the element separating all the rows. The default name is ROW. User can set this to NULL to suppress the ROW element itself. However, an error is produced if both the row and the rowset are NULL and there is more than one column or row in the output; this is because the generated XML would not have a top-level enclosing tag, and so would be invalid.
DBMS_XMLGEN.setRowTag ( ctx IN ctxHandle, rowTag IN VARCHAR2);
Sets the name of the root element of the document. The default name is ROWSET. User can set the rowSetTag NULL to suppress the printing of this element. However, an error is produced if both the row and the rowset are NULL and there is more than one column or row in the output; this is because the generated XML would not have a top-level enclosing tag, and so would be invalid.
DBMS_XMLGEN.setRowSetTag ( ctx IN ctxHandle, rowSetTag IN VARCHAR2);
Gets the XML document. When the rows indicated by the setSkipRows() call are skipped, the maximum number of rows as specified by the setMaxRows() call (or the entire result if not specified) is fetched and converted to XML. Use the getNumRowsProcessed() to check if any rows were retrieved. The available options are given in the following table.
Syntax | Description |
---|---|
dtdOrSchema IN number := NONE) RETURN boolean; |
This procedure gets the XML document by fetching the maximum number of rows specified. It appends the XML document to the CLOB passed in. Use this version of getXML() to avoid any extra CLOB copies and to reuse the same CLOB for subsequent calls. Because of the CLOB reuse, this getXML() call is potentially more efficient. |
dtdOrSchema IN number := NONE) RETURN clob; |
Generates the XML document and returns it as a temporary CLOB. The temporary CLOB obtained from this function must be freed using the DBMS_LOB.FREETEMPORARY call. |
dtdOrSchema IN number := NONE) RETURN clob; |
Converts the results from the SQL query string to XML format, and returns the XML as a temporary CLOB. This temporary CLOB must be subsequently freed using the DBMS_LOB.FREETEMPORARY call. |
FUNCTION DBMS_XMLGEN.getXMLType ( dtdOrSchema IN number := NONE) RETURN sys.XMLType; |
Generates the XML document and returns it as a sys.XMLType. XMLType operations can be performed on the results, including ExistsNode and Extract. This also provides a way of obtaining the results as a string by using the getStringVal() function, if the result size is less than 4K. |
FUNCTION DBMS_XMLGEN.getXMLType ( dtdOrSchema IN number := NONE) RETURN sys.XMLType |
Converts the results from the SQL query string to XML format, and returns the XML as a sys.XMLType. XMLType operations can be performed on the results, including ExistsNode and Extract. This also provides a way of obtaining the results as a string by using the getStringVal() function, if the result size is less than 4K. |
Retrieves the number of SQL rows processed when generating the XML using the getXML call; this count does not include the number of rows skipped before generating the XML. Used to determine the terminating condition if calling getXML() in a loop. Note that getXML() always generates an XML document, even if there are no rows present.
DBMS_XMLGEN.getNumRowsProcessed ( ctx IN ctxHandle) RETURN NUMBER;
Parameter | IN / OUT | Description |
---|---|---|
ctx |
(IN) |
The context handle obtained from the newContext call. |
Sets the maximum number of rows to fetch from the SQL query result for every invokation of the getXML call. Used when generating paginated results. For example, when generating a page of XML or HTML data, restrict the number of rows converted to XML or HTML by setting the maxRows parameter.
DBMS_XMLGEN.setMaxRows ( ctx IN ctxHandle, maxRows IN NUMBER);
Parameter | IN / OUT | Description |
---|---|---|
ctx |
(IN) |
The context handle corresponding to the query executed. |
maxRows |
(IN) |
The maximum number of rows to get for each call to getXML. |
Skips a given number of rows before generating the XML output for every call to the getXML routine. Used when generating paginated results for stateless Web pages using this utility. For example, when generating the first page of XML or HTML data, set skipRows to zero. For the next set, set the skipRows to the number of rows obtained in the first case. See getNumRowsProcessed().
DBMS_XMLGEN.setSkipRows ( ctx IN ctxHandle, skipRows IN NUMBER);
Parameter | IN / OUT | Description |
---|---|---|
ctx |
(IN) |
The context handle corresponding to the query executed. |
skipRows |
(IN) |
The number of rows to skip for each call to getXML. |
Sets whether or not special characters in the XML data must be converted into their escaped XML equivalent. For example, the < sign is converted to <. The default is to perform conversions. Improves performance of XML processing when the input data cannot contain any special characters such as <, >, ", ', which must be escaped. It is expensive to scan the character data to replace the special characters, particularly if it involves a lot of data. Syntax
DBMS_XMLGEN.setConvertSpecialChars ( ctx IN ctxHandle, conv IN boolean);
Parameter | IN / OUT | Description |
---|---|---|
ctx |
(IN) |
The context handle obtained from the newContext call. |
conv |
(IN) |
TRUE indicates that conversion is needed. |
Converts the XML data into the escaped or unescaped XML equivalent; returns XML CLOB data in encoded or decoded format. Escapes the XML data if the ENTITY_ENCODE is specified. For example, the escaped form of the character < is <. Unescaping is the reverse transformation. The available options are given in the following table.
Syntax | Description |
---|---|
flag IN NUMBER := ENTITY_ENCODE) RETURN VARCHAR2; |
Uses xmlData in string form (VARCHAR2). |
flag IN NUMBER := ENTITY_ENCODE) RETURN CLOB; |
Uses xmlData in Clob form. |
Parameter | IN / OUT | Description |
---|---|---|
xmlData |
(IN) |
The XML CLOB data to be encoded or decoded. |
flag |
(IN) |
The flag setting; ENTITY_ENCODE (default) for encode, and ENTITY_DECODE for decode. |
Overrides the default name of the collection elements. The default name for collection elements is the type name itself. Using this function, you can override the default to use the name of the column with the _ITEM tag appended to it. If there is a collection of NUMBER, the default tag name for the collection elements is NUMBER. Using this procedure, the user can override this behavior and generate the collection column name with the _ITEM tag appended to it.
DBMS_XMLGEN.useItemTagsForColl ( ctx IN ctxHandle);
Parameter | IN / OUT | Description |
---|---|---|
ctx |
(IN) |
The context handle. |
Restarts the query and generates the XML from the first row. Can be used to start executing the query again, without having to create a new context.
DBMS_XMLGEN.restartQUERY (ctx IN ctxHandle);
Parameter | IN / OUT | Description |
---|---|---|
ctx |
(IN) |
The context handle corresponding to the current query. |
Closes a given context and releases all resources associated with it, including the SQL cursor and bind and define buffers. After this call, the handle cannot be used for a subsequent DBMS_XMLGEN function call.
DBMS_XMLGEN.closeContext ( ctx IN ctxHandle);
Parameter | IN / OUT | Description |
---|---|---|
ctx |
(IN) |
The context handle to close. |
|
Copyright © 2001, 2002 Oracle Corporation. All Rights Reserved. |
|