Default function namespace declaration
The default function namespace declaration in the query prolog specifies a namespace URI that is used for unprefixed function names in function calls.
The query prolog can contain one default function namespace
declaration only. If no default function namespace is declared, the
default function namespace is the namespace of XPath and XQuery functions, http://www.w3.org/2005/xpath-functions
. If you declare
a default function namespace, you can invoke any function in the default
function namespace without specifying a prefix.
Db2 XQuery returns an error if the local name for an unprefixed function call does not match a function in the default function namespace.
Syntax
- function
- Specifies that the declaration is a default function namespace declaration
- URILiteral
- Specifies a string literal that represents the URI for the namespace. The string literal must be a valid URI or a zero-length string. If the string literal in a default function namespace declaration is a zero-length string, all function calls must use prefixed function names because every function is in some namespace.
Example
The following declaration specifies
that the default function namespace is associated with the URI http://www.ibm.com/xmlns/prod/db2/functions
:
declare default function namespace "http://www.ibm.com/xmlns/prod/db2/functions";
Within
the query body for this example, you could refer to any function in
the default function namespace without including a prefix in the function
name. This default function namespace includes the function xmlcolumn
,
so you can type xmlcolumn('T1.MYDOC')
instead of
typing db2-fn:xmlcolumn('T1.MYDOC')
. However, because
the default function namespace in this example is no longer associated
with the namespace for XQuery functions, you would need to specify
a prefix when you call XQuery built-in functions. For example, you
must type fn:current-date()
instead of typing current-date()
.