background image
<< XMLSERIALIZE operator | Built-in system functions >>

YEAR function

<< XMLSERIALIZE operator | Built-in system functions >>
Derby Reference Manual
150
Syntax
XMLSERIALIZE ( xml-value-expression AS string-data-type )
xml-value-expression
Can be any Derby XML value, including an XML result sequence generated by
the XMLQUERY operator. The
xml-value-expression
argument cannot be a
parameter.
string-data-type
Must be a SQL character string type, such as CHAR, VARCHAR, LONG VARCHAR,
or CLOB. If you specify a type that is not a valid character string type, Derby throws
an error.
Examples
In the
x_table
table, to display the contents of the
xcol
XML column, use this
statement:
SELECT ID,
XMLSERIALIZE(
xcol AS CLOB)
FROM x_table
To retrieve the results from JDBC, you can use the JDBC getCharacterStream() or
getString() method.
To display the results of an XMLQUERY operation, use the following statement:
SELECT ID,
XMLSERIALIZE(
XMLQUERY('//student[@age>20]'
PASSING BY REF xcol EMPTY ON EMPTY)
AS VARCHAR(50))
FROM x_table
Usage note
Derby requires that a JAXP parser (such as Apache Xerces) and Apache Xalan are listed
in the Java classpath for the XML functions to work. If either the JAXP parser or Xalan
is missing from the classpath, attempts to use the XMLSERIALIZE operator will result in
an error. In some situations, you may need to take steps to place the parser and Xalan in
your classpath. See "XML data types and operators" in the Derby Developer's Guide for
details.
YEAR function
The YEAR function returns the year part of a value. The argument must be a date,
timestamp, or a valid character string representation of a date or timestamp. The result of
the function is an integer between 1 and 9 999. If the argument can be null, the result can
be null; if the argument is null, the result is the null value.
Syntax
YEAR ( expression )
Example
Select all the projects in the PROJECT table that are scheduled to start (PRSTDATE)
and end (PRENDATE) in the same calendar year.
SELECT * FROM PROJECT WHERE YEAR(PRSTDATE) = YEAR(PRENDATE)