O'Reilly logo

Apache Derby—Off to the Races: Includes Details of IBM® Cloudscape™ by Dan Scott, George Baklarz, Paul C. Zikopoulos

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required