DB2 Version 10.1 for Linux, UNIX, and Windows

XML data type support in external routines

The programming languages C, C++, COBOL, Java, and .NET CLR support parameters and variables of data type XML.

External OLE and OLEDB routines do not support parameters of data type XML.

XML data type values are represented in external routine code in the same way as CLOB data types.

When declaring external routine parameters of data type XML, the CREATE PROCEDURE and CREATE FUNCTION statements that will be used to create the routines in the database must specify that the XML data type is to be stored as a CLOB data type. The size of the CLOB value should be close to the size of the XML document represented by the XML parameter.

The following CREATE PROCEDURE statement shows a CREATE PROCEDURE statement for an external procedure implemented in the C programming language with an XML parameter named parm1:
  CREATE PROCEDURE myproc(IN parm1 XML AS CLOB(2M), IN parm2 VARCHAR(32000))
  LANGUAGE C
  FENCED
  PARAMETER STYLE SQL
  EXTERNAL NAME 'mylib!myproc';
Similar considerations apply when creating external UDFs, as shown in the following example:
  CREATE FUNCTION myfunc (IN parm1 XML AS CLOB(2M))
  RETURNS SMALLINT
  LANGUAGE C
  PARAMETER STYLE SQL
  DETERMINISTIC
  NOT FENCED
  NULL CALL
  NO SQL
  NO EXTERNAL ACTION
  EXTERNAL NAME 'mylib1!myfunc'

XML data is materialized when passed to stored procedures as IN, OUT, or INOUT parameters. If you are using Java™ stored procedures, the heap size (java_heap_sz configuration parameter) might need to be increased based on the quantity and size of XML arguments, and the number of external stored procedures that are being executed concurrently.

Within external routine code, XML parameter and variable values are accessed, set, and modified in the same way as in database applications.