db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Morten Mikkelsen <mortenbr...@gmail.com>
Subject Re: Week number of the year CASE statement query
Date Sun, 21 Aug 2011 10:51:03 GMT
On Sun, Aug 21, 2011 at 12:41 PM, John English <john.foreign@gmail.com>wrote:

>
> Create a Java method:
>  public static final int weekNumber (java.sql.Date date) {
>    Calendar c = Calendar.getInstance();
>    c.setTime(date);
>    return c.get(Calendar.WEEK_OF_YEAR);
>  }
>
> Now create a function in SQL:
>  CREATE FUNCTION WeekNumber(theDate DATE)
>    RETURNS INTEGER
>    PARAMETER STYLE Java
>    LANGUAGE Java
>    EXTERNAL NAME 'packageName.ClassName.**weekNumber';
>
> ...and then just use "WeekNumber(aDate)" in the SELECT statement.
>
> A bit simpler than the ugly CASE!
>

Thanks!
If I understand correctly (doesn't get clearer from
http://db.apache.org/derby/docs/10.7/ref/rrefcreatefunctionstatement.html) the
java code must be compiled and present on the classpath of derby - or is it
possible to just feed the uncompiled java-code to derby?

Thanks,
-- 
/Morten

Mime
View raw message