You can write user-defined functions in Derby. Here's a nice blog with lots of step-by-step information: http://www.danvega.org/blog/2010/2/17/Creating-Apache-Derby-Custom-Functions-Part-2
And here's the Derby reference manual docs for the subject: http://db.apache.org/derby/docs/10.10/ref/rrefcreatefunctionstatement.html