User-Defined Functions

Chapter 8 introduced user-defined functions (UDFs). UDFs allow you to extend the functionality of SQL by introducing new functions that can be used as part of the SQL syntax. Apache Derby comes with many built-in functions; however, it is possible to create your own scalar functions. Scalar functions accept one or more values and return another value. A UDF must be written in Java and then defined to the database. For example, the following SQL will register a DSQRT (double square root) function using existing Java libraries.

CREATE FUNCTION DSQRT (DATA DOUBLE)
  RETURNS DOUBLE 
  EXTERNAL NAME 'java.lang.Math.sqrt' 
  LANGUAGE JAVA 
  PARAMETER STYLE JAVA;

values dsqrt(4);
1
----------------------
2.0

1 row selected

If a specific ...

Get Apache Derby—Off to the Races: Includes Details of IBM® Cloudscape™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.